@@ -500,23 +500,6 @@ async def _disconnect_raise(self, conn: Connection, error: Exception):
500
500
):
501
501
raise error
502
502
503
- async def _try_send_command_parse_response (self , conn , * args , ** options ):
504
- try :
505
- return await conn .retry .call_with_retry (
506
- lambda : self ._send_command_parse_response (
507
- conn , args [0 ], * args , ** options
508
- ),
509
- lambda error : self ._disconnect_raise (conn , error ),
510
- )
511
- except asyncio .CancelledError :
512
- await conn .disconnect (nowait = True )
513
- raise
514
- finally :
515
- if self .single_connection_client :
516
- self ._single_conn_lock .release ()
517
- if not self .connection :
518
- await self .connection_pool .release (conn )
519
-
520
503
# COMMAND EXECUTION AND PROTOCOL PARSING
521
504
async def execute_command (self , * args , ** options ):
522
505
"""Execute a command and return a parsed response"""
@@ -527,10 +510,18 @@ async def execute_command(self, *args, **options):
527
510
528
511
if self .single_connection_client :
529
512
await self ._single_conn_lock .acquire ()
530
-
531
- return await asyncio .shield (
532
- self ._try_send_command_parse_response (conn , * args , ** options )
533
- )
513
+ try :
514
+ return await conn .retry .call_with_retry (
515
+ lambda : self ._send_command_parse_response (
516
+ conn , command_name , * args , ** options
517
+ ),
518
+ lambda error : self ._disconnect_raise (conn , error ),
519
+ )
520
+ finally :
521
+ if self .single_connection_client :
522
+ self ._single_conn_lock .release ()
523
+ if not self .connection :
524
+ await pool .release (conn )
534
525
535
526
async def parse_response (
536
527
self , connection : Connection , command_name : Union [str , bytes ], ** options
@@ -774,18 +765,10 @@ async def _disconnect_raise_connect(self, conn, error):
774
765
is not a TimeoutError. Otherwise, try to reconnect
775
766
"""
776
767
await conn .disconnect ()
777
-
778
768
if not (conn .retry_on_timeout and isinstance (error , TimeoutError )):
779
769
raise error
780
770
await conn .connect ()
781
771
782
- async def _try_execute (self , conn , command , * arg , ** kwargs ):
783
- try :
784
- return await command (* arg , ** kwargs )
785
- except asyncio .CancelledError :
786
- await conn .disconnect ()
787
- raise
788
-
789
772
async def _execute (self , conn , command , * args , ** kwargs ):
790
773
"""
791
774
Connect manually upon disconnection. If the Redis server is down,
@@ -794,11 +777,9 @@ async def _execute(self, conn, command, *args, **kwargs):
794
777
called by the # connection to resubscribe us to any channels and
795
778
patterns we were previously listening to
796
779
"""
797
- return await asyncio .shield (
798
- conn .retry .call_with_retry (
799
- lambda : self ._try_execute (conn , command , * args , ** kwargs ),
800
- lambda error : self ._disconnect_raise_connect (conn , error ),
801
- )
780
+ return await conn .retry .call_with_retry (
781
+ lambda : command (* args , ** kwargs ),
782
+ lambda error : self ._disconnect_raise_connect (conn , error ),
802
783
)
803
784
804
785
async def parse_response (self , block : bool = True , timeout : float = 0 ):
@@ -1202,18 +1183,6 @@ async def _disconnect_reset_raise(self, conn, error):
1202
1183
await self .reset ()
1203
1184
raise
1204
1185
1205
- async def _try_send_command_parse_response (self , conn , * args , ** options ):
1206
- try :
1207
- return await conn .retry .call_with_retry (
1208
- lambda : self ._send_command_parse_response (
1209
- conn , args [0 ], * args , ** options
1210
- ),
1211
- lambda error : self ._disconnect_reset_raise (conn , error ),
1212
- )
1213
- except asyncio .CancelledError :
1214
- await conn .disconnect ()
1215
- raise
1216
-
1217
1186
async def immediate_execute_command (self , * args , ** options ):
1218
1187
"""
1219
1188
Execute a command immediately, but don't auto-retry on a
@@ -1229,8 +1198,12 @@ async def immediate_execute_command(self, *args, **options):
1229
1198
command_name , self .shard_hint
1230
1199
)
1231
1200
self .connection = conn
1232
- return await asyncio .shield (
1233
- self ._try_send_command_parse_response (conn , * args , ** options )
1201
+
1202
+ return await conn .retry .call_with_retry (
1203
+ lambda : self ._send_command_parse_response (
1204
+ conn , command_name , * args , ** options
1205
+ ),
1206
+ lambda error : self ._disconnect_reset_raise (conn , error ),
1234
1207
)
1235
1208
1236
1209
def pipeline_execute_command (self , * args , ** options ):
@@ -1398,19 +1371,6 @@ async def _disconnect_raise_reset(self, conn: Connection, error: Exception):
1398
1371
await self .reset ()
1399
1372
raise
1400
1373
1401
- async def _try_execute (self , conn , execute , stack , raise_on_error ):
1402
- try :
1403
- return await conn .retry .call_with_retry (
1404
- lambda : execute (conn , stack , raise_on_error ),
1405
- lambda error : self ._disconnect_raise_reset (conn , error ),
1406
- )
1407
- except asyncio .CancelledError :
1408
- # not supposed to be possible, yet here we are
1409
- await conn .disconnect (nowait = True )
1410
- raise
1411
- finally :
1412
- await self .reset ()
1413
-
1414
1374
async def execute (self , raise_on_error : bool = True ):
1415
1375
"""Execute all the commands in the current pipeline"""
1416
1376
stack = self .command_stack
@@ -1432,11 +1392,10 @@ async def execute(self, raise_on_error: bool = True):
1432
1392
conn = cast (Connection , conn )
1433
1393
1434
1394
try :
1435
- return await asyncio .shield (
1436
- self ._try_execute (conn , execute , stack , raise_on_error )
1395
+ return await conn .retry .call_with_retry (
1396
+ lambda : execute (conn , stack , raise_on_error ),
1397
+ lambda error : self ._disconnect_raise_reset (conn , error ),
1437
1398
)
1438
- except RuntimeError :
1439
- await self .reset ()
1440
1399
finally :
1441
1400
await self .reset ()
1442
1401
0 commit comments