Skip to content

Commit 22379e5

Browse files
committed
optimized execute_command thanks to github user Suor
1 parent cc61442 commit 22379e5

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

redis/client.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import threading
55
import time
66
import warnings
7-
from itertools import chain
7+
from itertools import chain, imap
88
from redis.exceptions import ConnectionError, ResponseError, InvalidResponse
99
from redis.exceptions import RedisError, AuthenticationError
1010

@@ -319,14 +319,11 @@ def _execute_command(self, command_name, command, **options):
319319

320320
def execute_command(self, *args, **options):
321321
"Sends the command to the redis server and returns it's response"
322-
cmd_count = len(args)
323-
cmds = []
324-
for i in args:
325-
enc_value = self.encode(i)
326-
cmds.append('$%s\r\n%s\r\n' % (len(enc_value), enc_value))
322+
cmds = ['$%s\r\n%s\r\n' % (len(enc_value), enc_value)
323+
for enc_value in imap(self.encode, args)]
327324
return self._execute_command(
328325
args[0],
329-
'*%s\r\n%s' % (cmd_count, ''.join(cmds)),
326+
'*%s\r\n%s' % (len(cmds), ''.join(cmds)),
330327
**options
331328
)
332329

0 commit comments

Comments
 (0)