summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Wolever <david@wolever.net>2011-07-13 16:33:40 -0400
committerDavid Wolever <david@wolever.net>2011-07-13 16:33:40 -0400
commit1292ca9e29d2c1343fa713d67cbdb7d3378e9dc3 (patch)
tree072dc54be976f4785bf7eb24a3f8cf6026884d2b
parent1f17b7538e490a5b5b19ee65e75b2f550e21a919 (diff)
downloadredis-py-1292ca9e29d2c1343fa713d67cbdb7d3378e9dc3.tar.gz
Fixing example to include `finally: pipe.reset()`
-rw-r--r--README.md48
1 files changed, 27 insertions, 21 deletions
diff --git a/README.md b/README.md
index 296e152..f65bd77 100644
--- a/README.md
+++ b/README.md
@@ -176,27 +176,33 @@ could do something like this:
>>> pipe = r.pipeline()
>>> while 1:
- >>> try:
- >>> # put a WATCH on the key that holds our sequence value
- >>> pipe.watch('OUR-SEQUENCE-KEY')
- >>> # after WATCHing, the pipeline is put into immediate execution
- >>> # mode until we tell it to start buffering commands again.
- >>> # this allows us to get the current value of our sequence
- >>> current_value = pipe.get('OUR-SEQUENCE-KEY')
- >>> next_value = int(current_value) + 1
- >>> # now we can put the pipeline back into buffered mode with MULTI
- >>> pipe.multi()
- >>> pipe.set('OUR-SEQUENCE-KEY', next_value)
- >>> # and finally, execute the pipeline (the set command)
- >>> pipe.execute()
- >>> # if a WatchError wasn't raised during execution, everything
- >>> # we just did happened atomically.
- >>> break
- >>> except WatchError:
- >>> # another client must have changed 'OUR-SEQUENCE-KEY' between
- >>> # the time we started WATCHing it and the pipeline's execution.
- >>> # our best bet is to just retry.
- >>> continue
+ ... try:
+ ... # put a WATCH on the key that holds our sequence value
+ ... pipe.watch('OUR-SEQUENCE-KEY')
+ ... # after WATCHing, the pipeline is put into immediate execution
+ ... # mode until we tell it to start buffering commands again.
+ ... # this allows us to get the current value of our sequence
+ ... current_value = pipe.get('OUR-SEQUENCE-KEY')
+ ... next_value = int(current_value) + 1
+ ... # now we can put the pipeline back into buffered mode with MULTI
+ ... pipe.multi()
+ ... pipe.set('OUR-SEQUENCE-KEY', next_value)
+ ... # and finally, execute the pipeline (the set command)
+ ... pipe.execute()
+ ... # if a WatchError wasn't raised during execution, everything
+ ... # we just did happened atomically.
+ ... break
+ ... except WatchError:
+ ... # another client must have changed 'OUR-SEQUENCE-KEY' between
+ ... # the time we started WATCHing it and the pipeline's execution.
+ ... # our best bet is to just retry.
+ ... continue
+ ... finally:
+ ... # Ensure that the pipe's connection has been returned to the
+ ... # pool (this will normally be done in `pipe.execute()`, but
+ ... # it should also be done here in case an exception is raised
+ ... # before `pip.execute()` can be called).
+ ... pipe.reset()
## API Reference