Skip to content

Commit 272d313

Browse files
committed
Slight optimization to command packing.
Fixed #1255
1 parent 9cbb48a commit 272d313

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
connections should require the server hostname to match the hostname
1919
specified in the SSL cert. By default 'ssl_check_hostname' is False
2020
for backwards compatibility. #1196
21+
* Slightly optimized command packing. Thanks @Deneby67. #1255
2122
* 3.3.11
2223
* Further fix for the SSLError -> TimeoutError mapping to work
2324
on obscure releases of Python 2.7.

redis/connection.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -757,15 +757,16 @@ def pack_command(self, *args):
757757
for arg in imap(self.encoder.encode, args):
758758
# to avoid large string mallocs, chunk the command into the
759759
# output list if we're sending large values
760-
if len(buff) > buffer_cutoff or len(arg) > buffer_cutoff:
760+
arg_length = len(arg)
761+
if len(buff) > buffer_cutoff or arg_length > buffer_cutoff:
761762
buff = SYM_EMPTY.join(
762-
(buff, SYM_DOLLAR, str(len(arg)).encode(), SYM_CRLF))
763+
(buff, SYM_DOLLAR, str(arg_length).encode(), SYM_CRLF))
763764
output.append(buff)
764765
output.append(arg)
765766
buff = SYM_CRLF
766767
else:
767768
buff = SYM_EMPTY.join(
768-
(buff, SYM_DOLLAR, str(len(arg)).encode(),
769+
(buff, SYM_DOLLAR, str(arg_length).encode(),
769770
SYM_CRLF, arg, SYM_CRLF))
770771
output.append(buff)
771772
return output

0 commit comments

Comments
 (0)