Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add materials for JSON.MERGE command. #59

Open
simonprickett opened this issue May 15, 2023 · 7 comments · May be fixed by #64
Open

Add materials for JSON.MERGE command. #59

simonprickett opened this issue May 15, 2023 · 7 comments · May be fixed by #64
Assignees
Labels
enhancement New feature or request

Comments

@simonprickett
Copy link
Contributor

When the JSON.MERGE command is available in the cloud, enhance the course with content for it.

@simonprickett
Copy link
Contributor Author

Do this at the same time as #60

@simonprickett
Copy link
Contributor Author

This should go in the course in or just after section 1.4 - Updating Data with RedisJSON.

@simonprickett
Copy link
Contributor Author

We should also update the code examples in section 2.2 to demonstrate this.

@simonprickett
Copy link
Contributor Author

Command examples - remove author, change content of editions, update pages, add has_ebook_version:

127.0.0.1:6379> JSON.MERGE ru204:book:274 $ '{"pages": 350, "editions": [ "english", "spanish", "french"], "author": null, "has_ebook_version": true}'
OK

Add the author back, remove has_ebook_version:

127.0.0.1:6379> JSON.MERGE ru204:book:274 $ '{"author": "S.E. Grove", "has_ebook_version": null }'
OK

@simonprickett
Copy link
Contributor Author

Also add example for when the key doesn't exist and when the path into the document doesn't exist but the document does.

@simonprickett
Copy link
Contributor Author

Add a fragment of a new book (where the key didn't exist already):

Check if the book exists...

127.0.0.1:6379> EXISTS ru204:book:9999
(integer) 0

Demo that you can only merge into the root when the key doesn't exist yet:

127.0.0.1:6379> JSON.MERGE ru204:book:9999 $.metrics '{"rating_votes": 22}'
(error) ERR new objects must be created at the root

Create a partial new book there:

127.0.0.1:6379> JSON.MERGE ru204:book:9999 $ '{"author": "Redis", "id": "9999"}'

OK

Tidy up:

127.0.0.1:6379> DEL ru204:book:9999
(integer) 1

@simonprickett
Copy link
Contributor Author

Also need to note that if you want to set a value to explicitly null you should use JSON.SET or JSON.MSET as JSON.MERGE will delete the value and its key completely.

@simonprickett simonprickett linked a pull request Aug 7, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant