question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pipeline.hget() returns StrictPipeline, NOT value of key

See original GitHub issue

I’m unable to use hget on a pipeline to get an actual key value:

red = redis.StrictRedis()
pl = red.pipeline()

ercnt = pl.hget(ecnt,rid)
logging.debug('Got error on action. ercnt="{}"'.format(ercnt))
# => DEBUG Got error on action.      
ercnt="StrictPipeline<ConnectionPool<Connection<host=localhost,port=6379,db=0>>>

If I replace above get with: errcnt=red.hget(ecnt,rid) I get a value. But I worry that its an unprotected one.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
andymccurdycommented, Dec 3, 2014

You’re on the right track with using WATCH. If you create a pipeline and execute the WATCH command, the pipeline is in a special mode where the commands you run will immediately execute and return until you run pl.multi(). So you can do something like this:

pl.watch('foo', 'bar')
# get some values from redis you need in the transaction
foo = pl.get('foo')
bar = pl.get('bar')

# switches to normal pipeline mode where commands get buffered
pl.multi()

# do some writes with the foo and bar values
pl.sadd(foo)
pl.sadd(bar)

# execute the pipeline
pl.execute()

Note that pl.execute() can raise a WatchError exception. Check out the pipeline section of the redis-py README: https://github.com/andymccurdy/redis-py/blob/master/README.rst#pipelines

I believe the second half of that section is exactly what you’re looking for, along with some convenience optimizations.

0reactions
punchacommented, May 7, 2017

Great! I was really confused that why the conditional checks can be used in Redis pipeline. Thanks for your explain on special mode.

Read more comments on GitHub >

github_iconTop Results From Across the Web

pipeline.hget() returns StrictPipeline, NOT value of key #563
The HGET doesn't get run until you run pl.execute() , which returns a list of the return values for each command.
Read more >
redis.client.StrictPipeline
Return the value at key ``name``, raises a KeyError if the key doesn't exist. ... LPOP a value off of the first non-empty...
Read more >
hincrby and hget returning True instead of actual value in ...
I have gone through the documentation and did google but still not able to figure out why hincrby is returning True in the...
Read more >
redis.client — TaskFlow documentation
return StrictPipeline ( self.connection_pool, self.response_callbacks, transaction, shard_hint) def transaction(self, func, *watches, ...
Read more >
RedPipe Documentation - Read the Docs
RedPipe makes pipeline commands work almost like non-pipelined commands in ... So grabbing the correct value from pipe.execute() is tricky.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found