summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhofmockel <dreagonfly@gmx.de>2013-04-17 15:30:00 +0200
committerhofmockel <dreagonfly@gmx.de>2013-04-17 15:30:00 +0200
commit01237e9efacf0f46fdf1adce502db152085fd7c1 (patch)
treee8ff6e3b4b6cbca141427ec81ebbd7376fded515
parent6d38b56db85b821cc5ef86527fcb1497deb80ad9 (diff)
downloadredis-py-01237e9efacf0f46fdf1adce502db152085fd7c1.tar.gz
Read all command responses of a pipeline
Otherwise a error makes the responses stuck in the socket. Which leads to wrong responses for the following commands
-rw-r--r--redis/client.py11
-rw-r--r--tests/pipeline.py15
2 files changed, 24 insertions, 2 deletions
diff --git a/redis/client.py b/redis/client.py
index a3359ae..e135776 100644
--- a/redis/client.py
+++ b/redis/client.py
@@ -1781,8 +1781,15 @@ class BasePipeline(object):
starmap(connection.pack_command,
[args for args, options in commands]))
connection.send_packed_command(all_cmds)
- response = [self.parse_response(connection, args[0], **options)
- for args, options in commands]
+
+ response = []
+ for args, options in commands:
+ try:
+ response.append(
+ self.parse_response(connection, args[0], **options))
+ except ResponseError as error:
+ response.append(error)
+
if raise_on_error:
self.raise_first_error(response)
return response
diff --git a/tests/pipeline.py b/tests/pipeline.py
index 138fecc..2f8967c 100644
--- a/tests/pipeline.py
+++ b/tests/pipeline.py
@@ -184,3 +184,18 @@ class PipelineTestCase(unittest.TestCase):
result = self.client.transaction(my_transaction, 'a', 'b')
self.assertEquals(result, [True])
self.assertEquals(self.client.get('c'), b('4'))
+
+ def test_error_in_simple_pipeline(self):
+ self.client.hmset('x', {'a': 'b'})
+ with self.client.pipeline(transaction=False) as pipe:
+ pipe.llen('x')
+ pipe.expire('x', 100)
+ try:
+ pipe.execute()
+ except redis.ResponseError:
+ pass
+ else:
+ raise
+
+ ret = self.client.hgetall('x')
+ self.assertEquals(ret, {'a': 'b'})