redis-py
redis-py copied to clipboard
Pipeline with JSON
When I have this:
r = redis.Redis()
pipe = r.pipeline(transaction=False)
pipe.jsonset('foo', '.', {'hello!': 'world'})
I get:
Pipeline object has no attribute 'jsonset'
When I have this:
r = redis.Redis()
pipe = r.json().pipeline()
pipe.jsonset('foo', '.', {'hello!': 'world'})
I get:
AttributeError: 'Redis" object has no attribute 'json'
What is the command to set a json value in the pipline method?
redis-pyv 4.3.4redis-serverv 6.2.3- w/ modules,
RedisJSONv 2.2.0
- w/ modules,
r = redis.Redis()
jp = r.json().pipeline()
jp.jsonset('foo', '.', {'hello':'world'})
jp.jsonget('foo', '.')
jp.execute()
[{'hello': 'world'}]
DeprecationWarning: Call to deprecated method jsonset. (redisjson-py supported this, call get directly.) -- Deprecated since version 4.0.0.
check redisjson-py #usage-example
or.. how do you think about using other types
like hash or something
@splurring can you add the versions you're using and if you're using Stack / what RedisJSON version you're running? I'm getting the same thing as @aciddust - the deprecation warning, but it works
@splurring the recommended way to do this nowadays is:
from redis import Redis
from redis.commands.json.path import Path
r = Redis()
pipe = r.pipeline()
pipe.json().set('test', Path.root_path(), {1: 1})
pipe.json().get('test', )
print(pipe.execute())
Feel free to reopen this issue if you have any problems with executing the JSON commands.