summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy McCurdy <andy@andymccurdy.com>2014-06-16 16:20:05 -0700
committerAndy McCurdy <andy@andymccurdy.com>2014-06-16 16:20:05 -0700
commitdffc6f97ce5cce454c07006e03b70c4cf41348bd (patch)
treea99b875873b35ae0227b288eb15c2a3c61759b36
parent1acc67ac789b9a4cc8f480fbf328ae4c711e29a0 (diff)
downloadredis-py-dffc6f97ce5cce454c07006e03b70c4cf41348bd.tar.gz
pack multiple commands in a pipeline into larger strings.
fixes #495
-rwxr-xr-xredis/client.py10
-rwxr-xr-xredis/connection.py16
2 files changed, 19 insertions, 7 deletions
diff --git a/redis/client.py b/redis/client.py
index 03a86ab..0ab8081 100755
--- a/redis/client.py
+++ b/redis/client.py
@@ -1,5 +1,5 @@
from __future__ import with_statement
-from itertools import chain, starmap
+from itertools import chain
import datetime
import sys
import warnings
@@ -2413,9 +2413,7 @@ class BasePipeline(object):
def _execute_transaction(self, connection, commands, raise_on_error):
cmds = chain([(('MULTI', ), {})], commands, [(('EXEC', ), {})])
- all_cmds = chain.from_iterable(
- starmap(connection.pack_command,
- [args for args, options in cmds]))
+ all_cmds = connection.pack_commands([args for args, _ in cmds])
connection.send_packed_command(all_cmds)
errors = []
@@ -2476,9 +2474,7 @@ class BasePipeline(object):
def _execute_pipeline(self, connection, commands, raise_on_error):
# build up all commands into a single request to increase network perf
- all_cmds = chain.from_iterable(
- starmap(connection.pack_command,
- [args for args, options in commands]))
+ all_cmds = connection.pack_commands([args for args, _ in commands])
connection.send_packed_command(all_cmds)
response = []
diff --git a/redis/connection.py b/redis/connection.py
index 40966e3..2123b33 100755
--- a/redis/connection.py
+++ b/redis/connection.py
@@ -598,6 +598,22 @@ class Connection(object):
output.append(buff)
return output
+ def pack_commands(self, commands):
+ "Pack multiple commands into the Redis protocol"
+ pieces = []
+ buff = ''
+
+ for cmd in commands:
+ packed = self.pack_command(*cmd)[0]
+ buff = SYM_EMPTY.join((buff, packed))
+ if len(buff) > 6000:
+ pieces.append(buff)
+ buff = ''
+
+ if buff:
+ pieces.append(buff)
+ return pieces
+
class SSLConnection(Connection):
description_format = "SSLConnection<host=%(host)s,port=%(port)s,db=%(db)s>"