Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View Commands in Pipeline in Redis-Py?

Tags:

python

redis

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)"]
like image 499
Eli Avatar asked Jun 28 '13 21:06

Eli


People also ask

How does Redis pipelining work?

Redis pipelining is a technique for improving performance by issuing multiple commands at once without waiting for the response to each individual command. Pipelining is supported by most Redis clients. This document describes the problem that pipelining is designed to solve and how pipelining works in Redis.

How do I check my Redis server status in Python?

Redis server connection can be checked by executing ping command to the server. using the ping method, we can handle reconnection etc. For knowing the reason for error in connecting, exception handling can be used as suggested in other answers.


1 Answers

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), {})]
like image 87
Pavel Anossov Avatar answered Oct 08 '22 10:10

Pavel Anossov