summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--redis/commands/json/__init__.py1
-rw-r--r--redis/commands/json/commands.py20
-rw-r--r--tests/test_asyncio/test_json.py9
-rw-r--r--tests/test_json.py9
4 files changed, 39 insertions, 0 deletions
diff --git a/redis/commands/json/__init__.py b/redis/commands/json/__init__.py
index 77fb21c..4f2a0c5 100644
--- a/redis/commands/json/__init__.py
+++ b/redis/commands/json/__init__.py
@@ -38,6 +38,7 @@ class JSON(JSONCommands):
"JSON.GET": self._decode,
"JSON.MGET": bulk_of_jsons(self._decode),
"JSON.SET": lambda r: r and nativestr(r) == "OK",
+ "JSON.MSET": lambda r: r and nativestr(r) == "OK",
"JSON.MERGE": lambda r: r and nativestr(r) == "OK",
"JSON.NUMINCRBY": self._decode,
"JSON.NUMMULTBY": self._decode,
diff --git a/redis/commands/json/commands.py b/redis/commands/json/commands.py
index 5da9245..3b2f2a5 100644
--- a/redis/commands/json/commands.py
+++ b/redis/commands/json/commands.py
@@ -253,6 +253,26 @@ class JSONCommands:
pieces.append("XX")
return self.execute_command("JSON.SET", *pieces)
+ def mset(self, name: str, path: str, obj: JsonType, *items) -> Optional[str]:
+ """
+ Set the JSON value at key ``name`` under the ``path`` to ``obj``
+ for one or more keys.
+
+ ``items`` accepts a list of additional key/path/value to set.
+
+ For the purpose of using this within a pipeline, this command is also
+ aliased to JSON.MSET.
+
+ For more information see `JSON.MSET <https://redis.io/commands/json.mset>`_.
+ """
+
+ pieces = [name, path, self._encode(obj)]
+
+ for key, path, value in zip(*[iter(items)] * 3):
+ pieces.extend([key, path, self._encode(value)])
+
+ return self.execute_command("JSON.MSET", *pieces)
+
def merge(
self,
name: str,
diff --git a/tests/test_asyncio/test_json.py b/tests/test_asyncio/test_json.py
index 7334399..fe160fc 100644
--- a/tests/test_asyncio/test_json.py
+++ b/tests/test_asyncio/test_json.py
@@ -110,6 +110,15 @@ async def test_mgetshouldsucceed(modclient: redis.Redis):
@pytest.mark.redismod
+@skip_ifmodversion_lt("2.6.0", "ReJSON") # todo: update after the release
+async def test_mset(modclient: redis.Redis):
+ await modclient.json().mset("1", Path.root_path(), 1, "2", Path.root_path(), 2)
+
+ assert await modclient.json().mget(["1"], Path.root_path()) == [1]
+ assert await modclient.json().mget(["1", "2"], Path.root_path()) == [1, 2]
+
+
+@pytest.mark.redismod
@skip_ifmodversion_lt("99.99.99", "ReJSON") # todo: update after the release
async def test_clear(modclient: redis.Redis):
await modclient.json().set("arr", Path.root_path(), [0, 1, 2, 3, 4])
diff --git a/tests/test_json.py b/tests/test_json.py
index 0a85998..ed448a0 100644
--- a/tests/test_json.py
+++ b/tests/test_json.py
@@ -116,6 +116,15 @@ def test_mgetshouldsucceed(client):
@pytest.mark.redismod
+@skip_ifmodversion_lt("2.6.0", "ReJSON") # todo: update after the release
+def test_mset(client):
+ client.json().mset("1", Path.root_path(), 1, "2", Path.root_path(), 2)
+
+ assert client.json().mget(["1"], Path.root_path()) == [1]
+ assert client.json().mget(["1", "2"], Path.root_path()) == [1, 2]
+
+
+@pytest.mark.redismod
@skip_ifmodversion_lt("99.99.99", "ReJSON") # todo: update after the release
def test_clear(client):
client.json().set("arr", Path.root_path(), [0, 1, 2, 3, 4])