diff options
author | andy <andy@whiskeymedia.com> | 2011-07-17 15:43:46 -0700 |
---|---|---|
committer | andy <andy@whiskeymedia.com> | 2011-07-17 15:43:46 -0700 |
commit | 4c750ee8b7385ca19a82d15c8d5597f84cbf7961 (patch) | |
tree | 53b77afba73d5655bb652d2fc09315d6e0070436 /README.md | |
parent | 2e185683e310513d4efdcf9ec212115383f03aff (diff) | |
download | redis-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.md | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -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 |