From 2ed7e3732d3c8263642291fd8aa7730c4fcdd690 Mon Sep 17 00:00:00 2001 From: Simon Prickett Date: Mon, 31 Jul 2023 15:15:36 +0100 Subject: [PATCH] Added text materials for JSON.MSET. --- .../ru204_1_4_0_updating_data_with_redisjson.html | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/courseware/html/section_1/ru204_1_4_0_updating_data_with_redisjson.html b/courseware/html/section_1/ru204_1_4_0_updating_data_with_redisjson.html index 1637fcfc..6cd8500c 100644 --- a/courseware/html/section_1/ru204_1_4_0_updating_data_with_redisjson.html +++ b/courseware/html/section_1/ru204_1_4_0_updating_data_with_redisjson.html @@ -78,4 +78,16 @@

Removing properties from a JSON document

JSON.DEL ru204:book:18161 $.genres

Redis returns the number of properties successfully removed; in this case one:

1

+

Updating multiple JSONPaths and/or documents at once

+
+

Each of the Redis commands that we've introduced so far works on a single JSON document (stored at a given Redis key) or on a single JSONPath into that document. When we want to update multiple documents and/or multiple paths into the same document at the same time, we can use the JSON.MSET command.

+

The JSON.MSET command was added in version 2.6.0 of RedisJSON. If your Redis Stack instance doesn't have this command, you'll need to upgrade it.

+

This command accepts one or more key name, JSONPath expression and value triplets as its arguments. It performs all of the updates in a single network round trip to the Redis server.

+

Let's see how JSON.MSET works by adding the has_ebook_version property to three more books at once: +

JSON.MSET ru204:book:16085 $.has_ebook_version true ru204:book:519 $.has_ebook_version false ru204:book:46 $.has_ebook_version true

+

Redis returns OK.

+

Next, let's update two properties of book 519 and a single property of book 46:

+

JSON.MSET ru204:book:519 $.metrics.score 3.5 ru204:book:519 $.has_ebook_version true ru204:book:46 $.has_ebook_version false

+

Redis returns OK.

+

Conclusion

While it is important to understand how to use the Redis CLI to use the RedisJSON commands to create and maintain documents within Redis, most developers will want to perform these operations from their application code directly. In the next section, we will explore how to manage JSON documents in Redis using popular Redis client libraries for commonly used programming languages.