Audit and make documentation for command JSON.MSET consistent #818
๐ Comprehensive Guide to JSON.MSET Command in DiceDB Overview The JSON.MSET command in DiceDB allows you to set multiple JSON values for different keys in a single, atomic operation. This is particularly useful for ensuring consistency when updating several keys at once. With JSON.MSET, all updates are applied together, or none are applied at all if an error occurs, preserving the integrity of your data.
โ๏ธ Parameters The JSON.MSET command requires an even number of arguments, where each argument pair consists of:
Key: The key to which the JSON value will be assigned. JSON Value: The actual JSON data you want to store. You can provide as many key-value pairs as needed. Hereโs the structure:
javascript Copy code JSON.MSET key1 json1 key2 json2 ... keyN jsonN Parameter Details: key1: The first key to set the JSON value. json1: The JSON value to be set at the first key. key2: The second key to set the JSON value. json2: The JSON value to be set at the second key. ...: Additional key-value pairs can follow this pattern. ๐ Command Example shell Copy code 127.0.0.1:6379> JSON.MSET user:1 '{"name": "Alice", "age": 30}' user:2 '{"name": "Bob", "age": 25}' OK In this example, two keys (user:1 and user:2) are set with their respective JSON values. The command returns OK, indicating that the operation was successful.
๐ฏ Return Value Upon success, the JSON.MSET command returns a simple string reply:
OK: If the operation is successful and all the key-value pairs are set. ๐ Behavior and Validation When the JSON.MSET command is executed, DiceDB performs the following actions:
Argument Validation: The number of arguments must be even (each key needs a corresponding JSON value). JSON Validation: Each JSON value is validated to ensure it's a valid JSON string. Atomic Operation: If all validations pass, DiceDB sets each key to its corresponding JSON value in one atomic operation, ensuring either all updates succeed, or none of them are applied. โ ๏ธ Error Handling The JSON.MSET command can raise errors in certain scenarios:
Odd Number of Arguments:
If you provide an odd number of arguments, DiceDB will return an error. Error Message: ERR wrong number of arguments for 'JSON.MSET' command. shell Copy code 127.0.0.1:6379> JSON.MSET user:1 '{"name": "Alice", "age": 30}' user:2 (error) ERR wrong number of arguments for 'JSON.MSET' command Invalid JSON String:
If any of the provided JSON values is not a valid JSON string, DiceDB will return an error. Error Message: ERR invalid JSON string. shell Copy code 127.0.0.1:6379> JSON.MSET user:1 '{"name": "Alice", "age": 30}' user:2 '{name: "Bob", age: 25}' (error) ERR invalid JSON string Other Errors:
Any other standard errors encountered by DiceDB during the operation will be reported similarly. ๐ Example Usage Setting Multiple JSON Values shell Copy code 127.0.0.1:6379> JSON.MSET user:1 '{"name": "Alice", "age": 30}' user:2 '{"name": "Bob", "age": 25}' OK Here, user:1 and user:2 are assigned their respective JSON values. The command returns OK, indicating both key-value pairs were successfully set.
Error Example: Odd Number of Arguments shell Copy code 127.0.0.1:6379> JSON.MSET user:1 '{"name": "Alice", "age": 30}' user:2 (error) ERR wrong number of arguments for 'JSON.MSET' command In this case, the command fails because it doesnโt have a corresponding JSON value for user:2.
Error Example: Invalid JSON shell Copy code 127.0.0.1:6379> JSON.MSET user:1 '{"name": "Alice", "age": 30}' user:2 '{name: "Bob", age: 25}' (error) ERR invalid JSON string The second JSON value is not valid, so DiceDB returns an error.
๐ฏ Best Practices Always ensure your JSON strings are well-formed and valid before using them in the JSON.MSET command. Double-check that you have an even number of arguments to avoid ERR wrong number of arguments errors. Use JSON.MSET for atomic operations involving multiple JSON keys to ensure that either all changes are applied or none, which is crucial for maintaining consistency in your database. ๐ Summary The JSON.MSET command in DiceDB is a powerful tool for updating multiple keys with JSON data in a single atomic transaction. Its error handling ensures that only valid operations are executed, while its simple return format (OK) makes it easy to confirm successful updates. Proper usage of this command can improve both efficiency and data integrity in applications that require the simultaneous update of multiple JSON objects.
Have converted this to draft PR till commit is fixed.
kidnly check latest one
@KunjShah95 please fix the commit, there are more than 368 files changed.
Have converted this to draft PR till commit is fixed.
sorry will not be able to help u
as i am still wondering how to fix it