summaryrefslogtreecommitdiff
path: root/redis/commands/json/commands.py
diff options
context:
space:
mode:
authorChayim I. Kirshen <c@kirshen.com>2021-11-01 17:52:32 +0200
committerChayim I. Kirshen <c@kirshen.com>2021-11-01 17:52:32 +0200
commit2bc2d6668661dcdd1c3ff5795f505a0e492f8bc2 (patch)
treec94fb691215ee0487b11c1e02f0512222c86518b /redis/commands/json/commands.py
parent8178997e2838d01dafe14dcf0a1d2d6c6a20f051 (diff)
downloadredis-py-ck-fixjson.tar.gz
Improvements to JSON coverageck-fixjson
tests to validate json behaviour deprecation support api changes
Diffstat (limited to 'redis/commands/json/commands.py')
-rw-r--r--redis/commands/json/commands.py55
1 files changed, 37 insertions, 18 deletions
diff --git a/redis/commands/json/commands.py b/redis/commands/json/commands.py
index 2f8039f..d0b3d99 100644
--- a/redis/commands/json/commands.py
+++ b/redis/commands/json/commands.py
@@ -1,5 +1,7 @@
from .path import Path, str_path
from .helpers import decode_dict_keys
+from deprecated import deprecated
+from redis.exceptions import DataError
class JSONCommands:
@@ -36,10 +38,6 @@ class JSONCommands:
pieces.append(self._encode(o))
return self.execute_command("JSON.ARRINSERT", *pieces)
- def forget(self, name, path=Path.rootPath()):
- """Alias for jsondel (delete the JSON value)."""
- return self.execute_command("JSON.FORGET", name, str_path(path))
-
def arrlen(self, name, path=Path.rootPath()):
"""Return the length of the array JSON value under ``path``
at key``name``.
@@ -86,6 +84,7 @@ class JSONCommands:
"JSON.NUMINCRBY", name, str_path(path), self._encode(number)
)
+ @deprecated(version='4.0.0', reason='deprecated since redisjson 1.0.0')
def nummultby(self, name, path, number):
"""Multiply the numeric (integer or floating point) JSON value under
``path`` at key ``name`` with the provided ``number``.
@@ -104,9 +103,12 @@ class JSONCommands:
"""
return self.execute_command("JSON.CLEAR", name, str_path(path))
- def delete(self, name, path=Path.rootPath()):
- """Delete the JSON value stored at key ``name`` under ``path``."""
- return self.execute_command("JSON.DEL", name, str_path(path))
+ def delete(self, key, path=Path.rootPath()):
+ """Delete the JSON value stored at key ``key`` under ``path``."""
+ return self.execute_command("JSON.DEL", key, str_path(path))
+
+ # forget is an alias for delete
+ forget = delete
def get(self, name, *args, no_escape=False):
"""
@@ -134,12 +136,13 @@ class JSONCommands:
except TypeError:
return None
- def mget(self, path, *args):
- """Get the objects stored as a JSON values under ``path`` from keys
- ``args``.
+ def mget(self, keys, path):
+ """
+ Get the objects stored as a JSON values under ``path``. ``keys``
+ is a list of one or more keys.
"""
pieces = []
- pieces.extend(args)
+ pieces += keys
pieces.append(str_path(path))
return self.execute_command("JSON.MGET", *pieces)
@@ -181,17 +184,33 @@ class JSONCommands:
"""
return self.execute_command("JSON.TOGGLE", name, str_path(path))
- def strappend(self, name, string, path=Path.rootPath()):
- """Append to the string JSON value under ``path`` at key ``name``
- the provided ``string``.
+ def strappend(self, name, *args):
+ """Append to the string JSON value. If two options are specified after
+ the key name, the path is determined to be the first. If a single
+ option is passed, then the rootpath (i.e Path.rootPath()) is used.
"""
+ pieces = [name]
+ if len(args) == 1:
+ pieces.append(Path.rootPath())
+ for a in args:
+ pieces.append(a)
+
return self.execute_command(
- "JSON.STRAPPEND", name, str_path(path), self._encode(string)
+ "JSON.STRAPPEND", *pieces
)
- def debug(self, name, path=Path.rootPath()):
+ def debug(self, subcommand, key=None, path=Path.rootPath()):
"""Return the memory usage in bytes of a value under ``path`` from
key ``name``.
"""
- return self.execute_command("JSON.DEBUG", "MEMORY",
- name, str_path(path))
+ valid_subcommands = ["MEMORY", "HELP"]
+ if subcommand not in valid_subcommands:
+ raise DataError("The only valid subcommands are ",
+ str(valid_subcommands))
+ pieces = [subcommand]
+ if subcommand == "MEMORY":
+ if key is None:
+ raise DataError("No key specified")
+ pieces.append(key)
+ pieces.append(str_path(path))
+ return self.execute_command("JSON.DEBUG", *pieces)