redis-py icon indicating copy to clipboard operation
redis-py copied to clipboard

Pipeline with JSON

Open splurring opened this issue 3 years ago • 2 comments

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?

splurring avatar Aug 11 '22 20:08 splurring

  • redis-py v 4.3.4
  • redis-server v 6.2.3
    • w/ modules, RedisJSON v 2.2.0
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

aciddust avatar Aug 23 '22 01:08 aciddust

@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

sav-norem avatar Sep 29 '22 16:09 sav-norem

@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.

uglide avatar Feb 08 '23 15:02 uglide