summaryrefslogtreecommitdiff
path: root/README.md
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 /README.md
parent2e185683e310513d4efdcf9ec212115383f03aff (diff)
downloadredis-py-4c750ee8b7385ca19a82d15c8d5597f84cbf7961.tar.gz
Added a `transaction` convenience method that eliminates boilerplate when
using pipelines while WATCHing variables.
Diffstat (limited to 'README.md')
-rw-r--r--README.md15
1 files changed, 15 insertions, 0 deletions
diff --git a/README.md b/README.md
index f77f627..2a0a18a 100644
--- a/README.md
+++ b/README.md
@@ -217,6 +217,21 @@ explicity calling reset():
... finally:
... pipe.reset()
+A convenience method named "transaction" exists for handling all the
+boilerplate of handling and retrying watch errors. It takes a callable that
+should expect a single parameter, a pipeline object, and any number of keys to
+be WATCHED. Our client-side INCR command above can be written like this,
+which is much easier to read:
+
+ >>> def client_side_incr(pipe):
+ ... current_value = pipe.get('OUR-SEQUENCE-KEY')
+ ... next_value = int(current_value) + 1
+ ... pipe.multi()
+ ... pipe.set('OUR-SEQUENCE-KEY', next_value)
+ >>>
+ >>> r.transaction(client_side_incr, 'OUR-SEQUENCE-KEY')
+ [True]
+
## API Reference