@@ -336,6 +336,7 @@ def _execute_command(self, command_name, command, **options):
336
336
if self .subscribed and not subscription_command :
337
337
raise RedisError ("Cannot issue commands other than SUBSCRIBE and "
338
338
"UNSUBSCRIBE while channels are open" )
339
+ command = self ._encode_command (command )
339
340
try :
340
341
self .connection .send (command , self )
341
342
if subscription_command :
@@ -347,14 +348,17 @@ def _execute_command(self, command_name, command, **options):
347
348
if subscription_command :
348
349
return None
349
350
return self .parse_response (command_name , ** options )
351
+
352
+ def _encode_command (self , args ):
353
+ cmds = ['$%s\r \n %s\r \n ' % (len (enc_value ), enc_value )
354
+ for enc_value in imap (self .encode , args )]
355
+ return '*%s\r \n %s' % (len (cmds ), '' .join (cmds ))
350
356
351
357
def execute_command (self , * args , ** options ):
352
358
"Sends the command to the redis server and returns it's response"
353
- cmds = ['$%s\r \n %s\r \n ' % (len (enc_value ), enc_value )
354
- for enc_value in imap (self .encode , args )]
355
359
return self ._execute_command (
356
360
args [0 ],
357
- '*%s \r \n %s' % ( len ( cmds ), '' . join ( cmds )) ,
361
+ args ,
358
362
** options
359
363
)
360
364
@@ -1426,10 +1430,10 @@ def _execute_command(self, command_name, command, **options):
1426
1430
def _execute_transaction (self , commands ):
1427
1431
# wrap the commands in MULTI ... EXEC statements to indicate an
1428
1432
# atomic operation
1429
- all_cmds = '' .join ([c for _1 , c , _2 in chain (
1430
- (('' , 'MULTI\r \n ' , '' ),),
1433
+ all_cmds = '' .join ([self . _encode_command ( c ) for _1 , c , _2 in chain (
1434
+ (('' , ( 'MULTI' ,) , '' ),),
1431
1435
commands ,
1432
- (('' , 'EXEC\r \n ' , '' ),)
1436
+ (('' , ( 'EXEC' ,) , '' ),)
1433
1437
)])
1434
1438
self .connection .send (all_cmds , self )
1435
1439
# parse off the response for MULTI and all commands prior to EXEC
@@ -1455,7 +1459,7 @@ def _execute_transaction(self, commands):
1455
1459
1456
1460
def _execute_pipeline (self , commands ):
1457
1461
# build up all commands into a single request to increase network perf
1458
- all_cmds = '' .join ([c for _1 , c , _2 in commands ])
1462
+ all_cmds = '' .join ([self . _encode_command ( c ) for _1 , c , _2 in commands ])
1459
1463
self .connection .send (all_cmds , self )
1460
1464
data = []
1461
1465
for command_name , _ , options in commands :
0 commit comments