2525 SentinelCommands ,
2626 list_or_args ,
2727)
28- from redis .connection import ConnectionPool , SSLConnection , UnixDomainSocketConnection
28+ from redis .connection import (
29+ AbstractConnection ,
30+ ConnectionPool ,
31+ SSLConnection ,
32+ UnixDomainSocketConnection ,
33+ )
2934from redis .credentials import CredentialProvider
3035from redis .exceptions import (
3136 ConnectionError ,
@@ -839,11 +844,15 @@ def clean_health_check_responses(self) -> None:
839844 def _disconnect_raise_connect (self , conn , error ) -> None :
840845 """
841846 Close the connection and raise an exception
842- if retry_on_timeout is not set or the error
843- is not a TimeoutError. Otherwise, try to reconnect
847+ if retry_on_error is not set or the error is not one
848+ of the specified error types. Otherwise, try to
849+ reconnect
844850 """
845851 conn .disconnect ()
846- if not (conn .retry_on_timeout and isinstance (error , TimeoutError )):
852+ if (
853+ conn .retry_on_error is None
854+ or isinstance (error , tuple (conn .retry_on_error )) is False
855+ ):
847856 raise error
848857 conn .connect ()
849858
@@ -1320,8 +1329,8 @@ def _disconnect_reset_raise(self, conn, error) -> None:
13201329 """
13211330 Close the connection, reset watching state and
13221331 raise an exception if we were watching,
1323- retry_on_timeout is not set,
1324- or the error is not a TimeoutError
1332+ if retry_on_error is not set or the error is not one
1333+ of the specified error types.
13251334 """
13261335 conn .disconnect ()
13271336 # if we were already watching a variable, the watch is no longer
@@ -1332,9 +1341,12 @@ def _disconnect_reset_raise(self, conn, error) -> None:
13321341 raise WatchError (
13331342 "A ConnectionError occurred on while watching one or more keys"
13341343 )
1335- # if retry_on_timeout is not set, or the error is not
1336- # a TimeoutError, raise it
1337- if not (conn .retry_on_timeout and isinstance (error , TimeoutError )):
1344+ # if retry_on_error is not set or the error is not one
1345+ # of the specified error types, raise it
1346+ if (
1347+ conn .retry_on_error is None
1348+ or isinstance (error , tuple (conn .retry_on_error )) is False
1349+ ):
13381350 self .reset ()
13391351 raise
13401352
@@ -1492,11 +1504,15 @@ def load_scripts(self):
14921504 if not exist :
14931505 s .sha = immediate ("SCRIPT LOAD" , s .script )
14941506
1495- def _disconnect_raise_reset (self , conn : Redis , error : Exception ) -> None :
1507+ def _disconnect_raise_reset (
1508+ self ,
1509+ conn : AbstractConnection ,
1510+ error : Exception ,
1511+ ) -> None :
14961512 """
14971513 Close the connection, raise an exception if we were watching,
1498- and raise an exception if TimeoutError is not part of retry_on_error,
1499- or the error is not a TimeoutError
1514+ and raise an exception if retry_on_error is not set or the
1515+ error is not one of the specified error types.
15001516 """
15011517 conn .disconnect ()
15021518 # if we were watching a variable, the watch is no longer valid
@@ -1506,11 +1522,13 @@ def _disconnect_raise_reset(self, conn: Redis, error: Exception) -> None:
15061522 raise WatchError (
15071523 "A ConnectionError occurred on while watching one or more keys"
15081524 )
1509- # if TimeoutError is not part of retry_on_error, or the error
1510- # is not a TimeoutError, raise it
1511- if not (
1512- TimeoutError in conn .retry_on_error and isinstance (error , TimeoutError )
1525+ # if retry_on_error is not set or the error is not one
1526+ # of the specified error types, raise it
1527+ if (
1528+ conn .retry_on_error is None
1529+ or isinstance (error , tuple (conn .retry_on_error )) is False
15131530 ):
1531+
15141532 self .reset ()
15151533 raise error
15161534
0 commit comments