@@ -500,23 +500,6 @@ async def _disconnect_raise(self, conn: Connection, error: Exception):
500500 ):
501501 raise error
502502
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-
520503 # COMMAND EXECUTION AND PROTOCOL PARSING
521504 async def execute_command (self , * args , ** options ):
522505 """Execute a command and return a parsed response"""
@@ -527,10 +510,18 @@ async def execute_command(self, *args, **options):
527510
528511 if self .single_connection_client :
529512 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 )
534525
535526 async def parse_response (
536527 self , connection : Connection , command_name : Union [str , bytes ], ** options
@@ -774,18 +765,10 @@ async def _disconnect_raise_connect(self, conn, error):
774765 is not a TimeoutError. Otherwise, try to reconnect
775766 """
776767 await conn .disconnect ()
777-
778768 if not (conn .retry_on_timeout and isinstance (error , TimeoutError )):
779769 raise error
780770 await conn .connect ()
781771
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-
789772 async def _execute (self , conn , command , * args , ** kwargs ):
790773 """
791774 Connect manually upon disconnection. If the Redis server is down,
@@ -794,11 +777,9 @@ async def _execute(self, conn, command, *args, **kwargs):
794777 called by the # connection to resubscribe us to any channels and
795778 patterns we were previously listening to
796779 """
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 ),
802783 )
803784
804785 async def parse_response (self , block : bool = True , timeout : float = 0 ):
@@ -816,7 +797,9 @@ async def parse_response(self, block: bool = True, timeout: float = 0):
816797 await conn .connect ()
817798
818799 read_timeout = None if block else timeout
819- response = await self ._execute (conn , conn .read_response , timeout = read_timeout )
800+ response = await self ._execute (
801+ conn , conn .read_response , timeout = read_timeout , disconnect_on_error = False
802+ )
820803
821804 if conn .health_check_interval and response == self .health_check_response :
822805 # ignore the health check message as user might not expect it
@@ -1200,18 +1183,6 @@ async def _disconnect_reset_raise(self, conn, error):
12001183 await self .reset ()
12011184 raise
12021185
1203- async def _try_send_command_parse_response (self , conn , * args , ** options ):
1204- try :
1205- return await conn .retry .call_with_retry (
1206- lambda : self ._send_command_parse_response (
1207- conn , args [0 ], * args , ** options
1208- ),
1209- lambda error : self ._disconnect_reset_raise (conn , error ),
1210- )
1211- except asyncio .CancelledError :
1212- await conn .disconnect ()
1213- raise
1214-
12151186 async def immediate_execute_command (self , * args , ** options ):
12161187 """
12171188 Execute a command immediately, but don't auto-retry on a
@@ -1227,8 +1198,12 @@ async def immediate_execute_command(self, *args, **options):
12271198 command_name , self .shard_hint
12281199 )
12291200 self .connection = conn
1230- return await asyncio .shield (
1231- 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 ),
12321207 )
12331208
12341209 def pipeline_execute_command (self , * args , ** options ):
@@ -1396,19 +1371,6 @@ async def _disconnect_raise_reset(self, conn: Connection, error: Exception):
13961371 await self .reset ()
13971372 raise
13981373
1399- async def _try_execute (self , conn , execute , stack , raise_on_error ):
1400- try :
1401- return await conn .retry .call_with_retry (
1402- lambda : execute (conn , stack , raise_on_error ),
1403- lambda error : self ._disconnect_raise_reset (conn , error ),
1404- )
1405- except asyncio .CancelledError :
1406- # not supposed to be possible, yet here we are
1407- await conn .disconnect (nowait = True )
1408- raise
1409- finally :
1410- await self .reset ()
1411-
14121374 async def execute (self , raise_on_error : bool = True ):
14131375 """Execute all the commands in the current pipeline"""
14141376 stack = self .command_stack
@@ -1430,11 +1392,10 @@ async def execute(self, raise_on_error: bool = True):
14301392 conn = cast (Connection , conn )
14311393
14321394 try :
1433- return await asyncio .shield (
1434- 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 ),
14351398 )
1436- except RuntimeError :
1437- await self .reset ()
14381399 finally :
14391400 await self .reset ()
14401401
0 commit comments