26
26
)
27
27
28
28
SYM_EMPTY = b ('' )
29
+ EMPTY_RESPONSE = 'EMPTY_RESPONSE'
29
30
30
31
31
32
def list_or_args (keys , args ):
@@ -757,7 +758,12 @@ def execute_command(self, *args, **options):
757
758
758
759
def parse_response (self , connection , command_name , ** options ):
759
760
"Parses a response from the Redis server"
760
- response = connection .read_response ()
761
+ try :
762
+ response = connection .read_response ()
763
+ except ResponseError :
764
+ if EMPTY_RESPONSE in options :
765
+ return options [EMPTY_RESPONSE ]
766
+ raise
761
767
if command_name in self .response_callbacks :
762
768
return self .response_callbacks [command_name ](response , ** options )
763
769
return response
@@ -1120,7 +1126,10 @@ def mget(self, keys, *args):
1120
1126
Returns a list of values ordered identically to ``keys``
1121
1127
"""
1122
1128
args = list_or_args (keys , args )
1123
- return self .execute_command ('MGET' , * args )
1129
+ options = {}
1130
+ if not args :
1131
+ options [EMPTY_RESPONSE ] = []
1132
+ return self .execute_command ('MGET' , * args , ** options )
1124
1133
1125
1134
def mset (self , * args , ** kwargs ):
1126
1135
"""
@@ -3214,7 +3223,8 @@ def pipeline_execute_command(self, *args, **options):
3214
3223
3215
3224
def _execute_transaction (self , connection , commands , raise_on_error ):
3216
3225
cmds = chain ([(('MULTI' , ), {})], commands , [(('EXEC' , ), {})])
3217
- all_cmds = connection .pack_commands ([args for args , _ in cmds ])
3226
+ all_cmds = connection .pack_commands ([args for args , options in cmds
3227
+ if EMPTY_RESPONSE not in options ])
3218
3228
connection .send_packed_command (all_cmds )
3219
3229
errors = []
3220
3230
@@ -3229,12 +3239,15 @@ def _execute_transaction(self, connection, commands, raise_on_error):
3229
3239
3230
3240
# and all the other commands
3231
3241
for i , command in enumerate (commands ):
3232
- try :
3233
- self .parse_response (connection , '_' )
3234
- except ResponseError :
3235
- ex = sys .exc_info ()[1 ]
3236
- self .annotate_exception (ex , i + 1 , command [0 ])
3237
- errors .append ((i , ex ))
3242
+ if EMPTY_RESPONSE in command [1 ]:
3243
+ errors .append ((i , command [1 ][EMPTY_RESPONSE ]))
3244
+ else :
3245
+ try :
3246
+ self .parse_response (connection , '_' )
3247
+ except ResponseError :
3248
+ ex = sys .exc_info ()[1 ]
3249
+ self .annotate_exception (ex , i + 1 , command [0 ])
3250
+ errors .append ((i , ex ))
3238
3251
3239
3252
# parse the EXEC.
3240
3253
try :
0 commit comments