DiceDB / dice

DiceDB is a redis-compliant, reactive, scalable, highly-available, unified cache optimized for modern hardware.
https://dicedb.io/
Other
6.75k stars 1.07k forks source link

Audit and make documentation for command `JSON.MSET` consistent #818

Open arpitbbhayani opened 1 month ago

arpitbbhayani commented 1 month ago

The documentation of the command [JSON.MSET](https://dicedb.io/commands/jsonmset/) present in the docs could have become stale. We need your help to ensure that the documentation is complete, correct, and consistent.  Completing this issue will give you much-needed exposure to how the command is implemented and the different parameters it accepts. Hence, this is a great way to build a good understanding of the project and its functionality. While still making a significant contribution. Here's what you need to do:

  1. Go through the documentation of the command and run all the examples, making sure they all work as expected
  2. If the same command is present in Redis, then the expected output of the DiceDB command is the same as the Redis output
  3. If the command is not in Redis, then as per your judgment, raise an issue with this template or fix the documentation and raise a pull request.
  4. The documentation should contain the following sections in the following order
    • short and concise introduction paragraph about the command covering what it does
    • Syntax
    • Parameters: List all the parameters the command accepts, and ignore the section if there are no parameters
    • Return values: List all possible return values and under what condition
    • Behaviour: Describe the behavior of the command, what it does, how it does it, some internal specifics if any
    • Errors: List all possible errors the command can throw and under what condition
    • Examples: List all possible examples of the command and the expected output. Assume CLI implementation

Note: The title of the sections should be the exact strings mentioned above, like "Examples", "Return values", etc. Note: The description of the command in Frontmatter of the command.md file is the first paragraph (introduction) of the command.

Go through the DiceDB/dice repository and explore the command implementation

Please use the documentation of the SET command as the reference point and structure the documentation of this command in a very similar way, including the following points

If you find any inconsistencies, please fix the documentation and raise the PR. The core idea of this exercise is to ensure that the documentation is consistent, correct, and complete.

Make sure you comment on the other issues you created (if any) as a comment on this issue and also any PR (if any) that you created. Thank you for picking this up and contributing to the DiceDB. It means a ton.

KunjShah95 commented 1 month ago

hey there @arpitbbhayani can i take up this issue. this seems a good starting point for me to start contributing to this repo.

lucifercr07 commented 1 month ago

@KunjShah95 assigned, thanks for contributing.

KunjShah95 commented 1 month ago

NOT ABLE TO PULL REUEST SO I AM ATTACHING THE ANSWER HERE 📚 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.

arpitbbhayani commented 1 month ago

Hello @KunjShah95,

There has been no activity on this issue for the past 5 days. It would be awesome if you keep posting updates to this issue so that we know you are actively working on it.

We are really eager to close this issue at the earliest, hence if we continue to see the inactivity, we will have to reassign the issue to someone else. We are doing this to ensure that the project maintains its momentum and others are not blocked on this work.

Just drop a comment with the current status of the work or share any issues you are facing. We can always chip in to help you out.

Thanks again.

KunjShah95 commented 1 month ago

Sorry I will not be able to help u due to stuck in previous workload so kindly reassign it to somebody else

arpitbbhayani commented 2 weeks ago

Hello @KunjShah95,

There has been no activity on this issue for the past 5 days. It would be awesome if you keep posting updates to this issue so that we know you are actively working on it.

We are really eager to close this issue at the earliest, hence if we continue to see the inactivity, we will have to reassign the issue to someone else. We are doing this to ensure that the project maintains its momentum and others are not blocked on this work.

Just drop a comment with the current status of the work or share any issues you are facing. We can always chip in to help you out.

Thanks again.

KunjShah95 commented 2 weeks ago

Kinslybassign it to someone else