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 ,
@@ -836,11 +841,15 @@ def clean_health_check_responses(self) -> None:
836841 def _disconnect_raise_connect (self , conn , error ) -> None :
837842 """
838843 Close the connection and raise an exception
839- if retry_on_timeout is not set or the error
840- is not a TimeoutError. Otherwise, try to reconnect
844+ if retry_on_error is not set or the error is not one
845+ of the specified error types. Otherwise, try to
846+ reconnect
841847 """
842848 conn .disconnect ()
843- if not (conn .retry_on_timeout and isinstance (error , TimeoutError )):
849+ if (
850+ conn .retry_on_error is None
851+ or isinstance (error , tuple (conn .retry_on_error )) is False
852+ ):
844853 raise error
845854 conn .connect ()
846855
@@ -1317,8 +1326,8 @@ def _disconnect_reset_raise(self, conn, error) -> None:
13171326 """
13181327 Close the connection, reset watching state and
13191328 raise an exception if we were watching,
1320- retry_on_timeout is not set,
1321- or the error is not a TimeoutError
1329+ if retry_on_error is not set or the error is not one
1330+ of the specified error types.
13221331 """
13231332 conn .disconnect ()
13241333 # if we were already watching a variable, the watch is no longer
@@ -1329,9 +1338,12 @@ def _disconnect_reset_raise(self, conn, error) -> None:
13291338 raise WatchError (
13301339 "A ConnectionError occurred on while watching one or more keys"
13311340 )
1332- # if retry_on_timeout is not set, or the error is not
1333- # a TimeoutError, raise it
1334- if not (conn .retry_on_timeout and isinstance (error , TimeoutError )):
1341+ # if retry_on_error is not set or the error is not one
1342+ # of the specified error types, raise it
1343+ if (
1344+ conn .retry_on_error is None
1345+ or isinstance (error , tuple (conn .retry_on_error )) is False
1346+ ):
13351347 self .reset ()
13361348 raise
13371349
@@ -1489,11 +1501,15 @@ def load_scripts(self):
14891501 if not exist :
14901502 s .sha = immediate ("SCRIPT LOAD" , s .script )
14911503
1492- def _disconnect_raise_reset (self , conn : Redis , error : Exception ) -> None :
1504+ def _disconnect_raise_reset (
1505+ self ,
1506+ conn : AbstractConnection ,
1507+ error : Exception ,
1508+ ) -> None :
14931509 """
14941510 Close the connection, raise an exception if we were watching,
1495- and raise an exception if TimeoutError is not part of retry_on_error,
1496- or the error is not a TimeoutError
1511+ and raise an exception if retry_on_error is not set or the
1512+ error is not one of the specified error types.
14971513 """
14981514 conn .disconnect ()
14991515 # if we were watching a variable, the watch is no longer valid
@@ -1503,11 +1519,13 @@ def _disconnect_raise_reset(self, conn: Redis, error: Exception) -> None:
15031519 raise WatchError (
15041520 "A ConnectionError occurred on while watching one or more keys"
15051521 )
1506- # if TimeoutError is not part of retry_on_error, or the error
1507- # is not a TimeoutError, raise it
1508- if not (
1509- TimeoutError in conn .retry_on_error and isinstance (error , TimeoutError )
1522+ # if retry_on_error is not set or the error is not one
1523+ # of the specified error types, raise it
1524+ if (
1525+ conn .retry_on_error is None
1526+ or isinstance (error , tuple (conn .retry_on_error )) is False
15101527 ):
1528+
15111529 self .reset ()
15121530 raise error
15131531
0 commit comments