summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRandall Leeds <randall.leeds@gmail.com>2011-07-11 20:21:43 -0700
committerRandall Leeds <randall.leeds@gmail.com>2011-07-11 20:21:43 -0700
commita7c9d06cc635ffde98ab2f29350799e23b00b4b3 (patch)
treee49c5ef1065311106ab38fffedb44ccf1df3e254
parent7a40f7da6e1bf812e94b94d1863321cc792015dd (diff)
downloadredis-py-a7c9d06cc635ffde98ab2f29350799e23b00b4b3.tar.gz
reset() and unwatch should react to responses
self.watching should not be set to True until a successful response from a WATCH is received. We can simplify management of this variable by completing the response cycle with an overridden parse_response().
-rw-r--r--redis/client.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/redis/client.py b/redis/client.py
index b68c1df..ee90c24 100644
--- a/redis/client.py
+++ b/redis/client.py
@@ -1202,6 +1202,9 @@ class Pipeline(Redis):
ResponseError exceptions, such as those raised when issuing a command
on a key of a different datatype.
"""
+
+ UNWATCH_COMMANDS = set(('DISCARD', 'EXEC', 'UNWATCH'))
+
def __init__(self, connection_pool, response_callbacks, transaction,
shard_hint):
self.connection_pool = connection_pool
@@ -1326,6 +1329,13 @@ class Pipeline(Redis):
return [self.parse_response(connection, args[0], **options)
for args, options in commands]
+ def parse_response(self, connection, command_name, **options):
+ if command_name in self.__class__.UNWATCH_COMMANDS:
+ self.watching = False
+ if command_name is 'WATCH':
+ self.watching = True
+ return Redis.parse_response(self, connection, command_name, **options)
+
def execute(self):
"Execute all the commands in the current pipeline"
stack = self.command_stack
@@ -1365,9 +1375,6 @@ class Pipeline(Redis):
response = self.execute_command('UNWATCH')
else:
response = True
- # it's safe to reset() here because we are no longer bound to a
- # single connection and we're sure the command stack is empty.
- self.reset()
return response
class LockError(RedisError):