Skip to content

Commit

Permalink
better pack_commands algorithm with less string joining
Browse files Browse the repository at this point in the history
  • Loading branch information
andymccurdy committed Jul 4, 2014
1 parent bd28b48 commit 246db5b
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions redis/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,19 +600,23 @@ def pack_command(self, *args):

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):
Expand Down

0 comments on commit 246db5b

Please sign in to comment.