summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy McCurdy <andy@andymccurdy.com>2014-06-17 09:08:35 -0700
committerAndy McCurdy <andy@andymccurdy.com>2014-07-03 21:53:12 -0700
commit246db5b13c5b3c21263b9db42ebefaeb963d5bb9 (patch)
treef74331322f4abd2b346e276a28a521f0de32ee9c
parentbd28b48b143e736c672b90561175e85e6223c86c (diff)
downloadredis-py-246db5b13c5b3c21263b9db42ebefaeb963d5bb9.tar.gz
better pack_commands algorithm with less string joining
-rwxr-xr-xredis/connection.py22
1 files changed, 13 insertions, 9 deletions
diff --git a/redis/connection.py b/redis/connection.py
index f9efa7b..141731d 100755
--- a/redis/connection.py
+++ b/redis/connection.py
@@ -600,19 +600,23 @@ class Connection(object):
def pack_commands(self, commands):
"Pack multiple commands into the Redis protocol"
+ output = []
pieces = []
- buff = SYM_EMPTY
+ buffer_length = 0
for cmd in commands:
packed = self.pack_command(*cmd)[0]
- buff = SYM_EMPTY.join((buff, packed))
- if len(buff) > 6000:
- pieces.append(buff)
- buff = SYM_EMPTY
-
- if buff:
- pieces.append(buff)
- return pieces
+ pieces.append(packed)
+ buffer_length += len(packed)
+
+ if buffer_length > 6000:
+ output.append(SYM_EMPTY.join(pieces))
+ buffer_length = 0
+ pieces = []
+
+ if pieces:
+ output.append(SYM_EMPTY.join(pieces))
+ return output
class SSLConnection(Connection):