1919 SentinelCommands ,
2020 list_or_args ,
2121)
22- from redis .connection import ConnectionPool , SSLConnection , UnixDomainSocketConnection
22+ from redis .connection import (
23+ AbstractConnection ,
24+ ConnectionPool ,
25+ SSLConnection ,
26+ UnixDomainSocketConnection ,
27+ )
2328from redis .credentials import CredentialProvider
2429from redis .exceptions import (
2530 ConnectionError ,
@@ -783,11 +788,15 @@ def clean_health_check_responses(self) -> None:
783788 def _disconnect_raise_connect (self , conn , error ) -> None :
784789 """
785790 Close the connection and raise an exception
786- if retry_on_timeout is not set or the error
787- is not a TimeoutError. Otherwise, try to reconnect
791+ if retry_on_error is not set or the error is not one
792+ of the specified error types. Otherwise, try to
793+ reconnect
788794 """
789795 conn .disconnect ()
790- if not (conn .retry_on_timeout and isinstance (error , TimeoutError )):
796+ if (
797+ conn .retry_on_error is None
798+ or isinstance (error , tuple (conn .retry_on_error )) is False
799+ ):
791800 raise error
792801 conn .connect ()
793802
@@ -1263,8 +1272,8 @@ def _disconnect_reset_raise(self, conn, error) -> None:
12631272 """
12641273 Close the connection, reset watching state and
12651274 raise an exception if we were watching,
1266- retry_on_timeout is not set,
1267- or the error is not a TimeoutError
1275+ if retry_on_error is not set or the error is not one
1276+ of the specified error types.
12681277 """
12691278 conn .disconnect ()
12701279 # if we were already watching a variable, the watch is no longer
@@ -1275,9 +1284,12 @@ def _disconnect_reset_raise(self, conn, error) -> None:
12751284 raise WatchError (
12761285 "A ConnectionError occurred on while watching one or more keys"
12771286 )
1278- # if retry_on_timeout is not set, or the error is not
1279- # a TimeoutError, raise it
1280- if not (conn .retry_on_timeout and isinstance (error , TimeoutError )):
1287+ # if retry_on_error is not set or the error is not one
1288+ # of the specified error types, raise it
1289+ if (
1290+ conn .retry_on_error is None
1291+ or isinstance (error , tuple (conn .retry_on_error )) is False
1292+ ):
12811293 self .reset ()
12821294 raise
12831295
@@ -1435,11 +1447,15 @@ def load_scripts(self):
14351447 if not exist :
14361448 s .sha = immediate ("SCRIPT LOAD" , s .script )
14371449
1438- def _disconnect_raise_reset (self , conn : Redis , error : Exception ) -> None :
1450+ def _disconnect_raise_reset (
1451+ self ,
1452+ conn : AbstractConnection ,
1453+ error : Exception ,
1454+ ) -> None :
14391455 """
14401456 Close the connection, raise an exception if we were watching,
1441- and raise an exception if TimeoutError is not part of retry_on_error,
1442- or the error is not a TimeoutError
1457+ and raise an exception if retry_on_error is not set or the
1458+ error is not one of the specified error types.
14431459 """
14441460 conn .disconnect ()
14451461 # if we were watching a variable, the watch is no longer valid
@@ -1449,11 +1465,13 @@ def _disconnect_raise_reset(self, conn: Redis, error: Exception) -> None:
14491465 raise WatchError (
14501466 "A ConnectionError occurred on while watching one or more keys"
14511467 )
1452- # if TimeoutError is not part of retry_on_error, or the error
1453- # is not a TimeoutError, raise it
1454- if not (
1455- TimeoutError in conn .retry_on_error and isinstance (error , TimeoutError )
1468+ # if retry_on_error is not set or the error is not one
1469+ # of the specified error types, raise it
1470+ if (
1471+ conn .retry_on_error is None
1472+ or isinstance (error , tuple (conn .retry_on_error )) is False
14561473 ):
1474+
14571475 self .reset ()
14581476 raise error
14591477
0 commit comments