andymccurdy/redis-py — pull request #206 by dvirsky (2011-10-22 22:42:12+00:00)
Title: PipelineContext module

Hi Andy,
I've created a little convenience wrapper around pipelines, that saves a lot of code and beautifies handling the result.

It's done using 2 tricks:
1. pipelines are used as context managers.
2. buffered result objects are returned when calling commands on the pipeline, and they can access the data after the execution.

e.g.:
```python
>>> from pipeline_context import *
>>> r = redis.Redis()
>>> r.set('foo', 'bar')
>>> r.sadd('bar', 'baz')

>>> with PipelineContext(connection = r) as p:
... x = p.get('foo')
... y = p.smembers('bar')
...
>>> x()
'bar'
>>> y()
set(['baz'])
>>>
```
If you want to include this in redis-py I'd be honored :)
currently I'm not doing any special treating of exceptions during redis execution, but it maybe okay, as you can simply wrap the whole context inside a try block