diff options
Diffstat (limited to 'redis/commands/json')
-rw-r--r-- | redis/commands/json/__init__.py | 27 | ||||
-rw-r--r-- | redis/commands/json/commands.py | 18 |
2 files changed, 45 insertions, 0 deletions
diff --git a/redis/commands/json/__init__.py b/redis/commands/json/__init__.py index d00627e..d634dbd 100644 --- a/redis/commands/json/__init__.py +++ b/redis/commands/json/__init__.py @@ -6,6 +6,7 @@ from .decoders import ( ) from ..helpers import nativestr from .commands import JSONCommands +import redis class JSON(JSONCommands): @@ -91,3 +92,29 @@ class JSON(JSONCommands): def _encode(self, obj): """Get the encoder.""" return self.__encoder__.encode(obj) + + def pipeline(self, transaction=True, shard_hint=None): + """Creates a pipeline for the JSON module, that can be used for executing + JSON commands, as well as classic core commands. + + Usage example: + + r = redis.Redis() + pipe = r.json().pipeline() + pipe.jsonset('foo', '.', {'hello!': 'world'}) + pipe.jsonget('foo') + pipe.jsonget('notakey') + """ + p = Pipeline( + connection_pool=self.client.connection_pool, + response_callbacks=self.MODULE_CALLBACKS, + transaction=transaction, + shard_hint=shard_hint, + ) + p._encode = self._encode + p._decode = self._decode + return p + + +class Pipeline(JSONCommands, redis.client.Pipeline): + """Pipeline for the module.""" diff --git a/redis/commands/json/commands.py b/redis/commands/json/commands.py index 716741c..4436f6a 100644 --- a/redis/commands/json/commands.py +++ b/redis/commands/json/commands.py @@ -154,6 +154,9 @@ class JSONCommands: ``xx`` if set to True, set ``value`` only if it exists. ``decode_keys`` If set to True, the keys of ``obj`` will be decoded with utf-8. + + For the purpose of using this within a pipeline, this command is also + aliased to jsonset. """ if decode_keys: obj = decode_dict_keys(obj) @@ -212,3 +215,18 @@ class JSONCommands: pieces.append(key) pieces.append(str(path)) return self.execute_command("JSON.DEBUG", *pieces) + + @deprecated(version='4.0.0', + reason='redisjson-py supported this, call get directly.') + def jsonget(self, *args, **kwargs): + return self.get(*args, **kwargs) + + @deprecated(version='4.0.0', + reason='redisjson-py supported this, call get directly.') + def jsonmget(self, *args, **kwargs): + return self.mget(*args, **kwargs) + + @deprecated(version='4.0.0', + reason='redisjson-py supported this, call get directly.') + def jsonset(self, *args, **kwargs): + return self.set(*args, **kwargs) |