Skip to content

Commit

Permalink
add an example for pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
thefab committed Feb 21, 2015
1 parent 8b32741 commit dfa492f
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions examples/pipeline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import tornado
import tornadis


@tornado.gen.coroutine
def pipeline_coroutine():
# Let's get a connected client
client = tornadis.Client()
yield client.connect()

# Let's make a pipeline object to stack commands inside
pipeline = tornadis.Pipeline()
pipeline.stack_call("SET", "foo", "bar")
pipeline.stack_call("GET", "foo")

# At this point, nothing is sent to redis

# Let's submit the pipeline to redis and wait for replies
results = yield client.call(pipeline)

# The two replies are in the results array
print results
# >>> ['OK', 'bar']

# Let's disconnect
client.disconnect()


def stop_loop(future):
exception = future.exception()
if exception is not None:
raise(exception)
loop.stop()


loop = tornado.ioloop.IOLoop.instance()
loop.add_future(pipeline_coroutine(), stop_loop)
loop.start()

0 comments on commit dfa492f

Please sign in to comment.