Eli
Eli

Reputation: 38949

View Commands in Pipeline in Redis-Py?

Is there a simple way to just view the commands that have been queued up in a pipeline in Redis-Py? I can't find anything in the documentation about this, but it seems like a trivial and useful command. I'd just want to do something like:

p = redis_conn.pipeline()
p.hset('blah', 'meh', 1)
p.hset('foo', 'bar', 1)
print p.view() #returns ["hset('blah', 'meh', 1)", "hset('foo', 'bar', 1)"]

Upvotes: 6

Views: 1419

Answers (1)

Pavel Anossov
Pavel Anossov

Reputation: 62908

You can inspect the command_stack:

In [17]: p.hset('blah', 'meh', 1)
Out[17]: <redis.client.StrictPipeline at 0x10d4dde90>

In [18]: p.hset('foo', 'bar', 1)
Out[18]: <redis.client.StrictPipeline at 0x10d4dde90>

In [19]: p.command_stack
Out[19]: [(('HSET', 'blah', 'meh', 1), {}), (('HSET', 'foo', 'bar', 1), {})]

Upvotes: 8

Related Questions