summaryrefslogtreecommitdiff
path: root/redis/client.py
diff options
context:
space:
mode:
authorandy <andy@whiskeymedia.com>2011-07-17 15:43:46 -0700
committerandy <andy@whiskeymedia.com>2011-07-17 15:43:46 -0700
commit4c750ee8b7385ca19a82d15c8d5597f84cbf7961 (patch)
tree53b77afba73d5655bb652d2fc09315d6e0070436 /redis/client.py
parent2e185683e310513d4efdcf9ec212115383f03aff (diff)
downloadredis-py-4c750ee8b7385ca19a82d15c8d5597f84cbf7961.tar.gz
Added a `transaction` convenience method that eliminates boilerplate when
using pipelines while WATCHing variables.
Diffstat (limited to 'redis/client.py')
-rw-r--r--redis/client.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/redis/client.py b/redis/client.py
index 9ab467f..1c245bf 100644
--- a/redis/client.py
+++ b/redis/client.py
@@ -203,6 +203,22 @@ class Redis(object):
transaction,
shard_hint)
+ def transaction(self, func, *watches, **kwargs):
+ """
+ Convenience method for executing the callable `func` as a transaction
+ while watching all keys specified in `watches`. The 'func' callable
+ should expect a single arguement which is a Pipeline object.
+ """
+ shard_hint = kwargs.pop('shard_hint', None)
+ with self.pipeline(True, shard_hint) as pipe:
+ while 1:
+ try:
+ pipe.watch(*watches)
+ func(pipe)
+ return pipe.execute()
+ except WatchError:
+ continue
+
def lock(self, name, timeout=None, sleep=0.1):
"""
Return a new Lock object using key ``name`` that mimics