25
25
SentinelCommands ,
26
26
list_or_args ,
27
27
)
28
- from redis .connection import ConnectionPool , SSLConnection , UnixDomainSocketConnection
28
+ from redis .connection import (
29
+ ConnectionPool ,
30
+ SSLConnection ,
31
+ UnixDomainSocketConnection ,
32
+ AbstractConnection ,
33
+ )
29
34
from redis .credentials import CredentialProvider
30
35
from redis .exceptions import (
31
36
ConnectionError ,
@@ -837,11 +842,15 @@ def clean_health_check_responses(self) -> None:
837
842
def _disconnect_raise_connect (self , conn , error ) -> None :
838
843
"""
839
844
Close the connection and raise an exception
840
- if retry_on_timeout is not set or the error
841
- is not a TimeoutError. Otherwise, try to reconnect
845
+ if retry_on_error is not set or the error is not one
846
+ of the specified error types. Otherwise, try to
847
+ reconnect
842
848
"""
843
849
conn .disconnect ()
844
- if not (conn .retry_on_timeout and isinstance (error , TimeoutError )):
850
+ if (
851
+ conn .retry_on_error is None
852
+ or isinstance (error , tuple (conn .retry_on_error )) is False
853
+ ):
845
854
raise error
846
855
conn .connect ()
847
856
@@ -1318,8 +1327,8 @@ def _disconnect_reset_raise(self, conn, error) -> None:
1318
1327
"""
1319
1328
Close the connection, reset watching state and
1320
1329
raise an exception if we were watching,
1321
- retry_on_timeout is not set,
1322
- or the error is not a TimeoutError
1330
+ if retry_on_error is not set or the error is not one
1331
+ of the specified error types.
1323
1332
"""
1324
1333
conn .disconnect ()
1325
1334
# if we were already watching a variable, the watch is no longer
@@ -1330,9 +1339,12 @@ def _disconnect_reset_raise(self, conn, error) -> None:
1330
1339
raise WatchError (
1331
1340
"A ConnectionError occurred on while watching one or more keys"
1332
1341
)
1333
- # if retry_on_timeout is not set, or the error is not
1334
- # a TimeoutError, raise it
1335
- if not (conn .retry_on_timeout and isinstance (error , TimeoutError )):
1342
+ # if retry_on_error is not set or the error is not one
1343
+ # of the specified error types, raise it
1344
+ if (
1345
+ conn .retry_on_error is None
1346
+ or isinstance (error , tuple (conn .retry_on_error )) is False
1347
+ ):
1336
1348
self .reset ()
1337
1349
raise
1338
1350
@@ -1490,11 +1502,15 @@ def load_scripts(self):
1490
1502
if not exist :
1491
1503
s .sha = immediate ("SCRIPT LOAD" , s .script )
1492
1504
1493
- def _disconnect_raise_reset (self , conn : Redis , error : Exception ) -> None :
1505
+ def _disconnect_raise_reset (
1506
+ self ,
1507
+ conn : AbstractConnection ,
1508
+ error : Exception ,
1509
+ ) -> None :
1494
1510
"""
1495
1511
Close the connection, raise an exception if we were watching,
1496
- and raise an exception if TimeoutError is not part of retry_on_error,
1497
- or the error is not a TimeoutError
1512
+ and raise an exception if retry_on_error is not set or the
1513
+ error is not one of the specified error types.
1498
1514
"""
1499
1515
conn .disconnect ()
1500
1516
# if we were watching a variable, the watch is no longer valid
@@ -1504,11 +1520,13 @@ def _disconnect_raise_reset(self, conn: Redis, error: Exception) -> None:
1504
1520
raise WatchError (
1505
1521
"A ConnectionError occurred on while watching one or more keys"
1506
1522
)
1507
- # if TimeoutError is not part of retry_on_error, or the error
1508
- # is not a TimeoutError, raise it
1509
- if not (
1510
- TimeoutError in conn .retry_on_error and isinstance (error , TimeoutError )
1523
+ # if retry_on_error is not set or the error is not one
1524
+ # of the specified error types, raise it
1525
+ if (
1526
+ conn .retry_on_error is None
1527
+ or isinstance (error , tuple (conn .retry_on_error )) is False
1511
1528
):
1529
+
1512
1530
self .reset ()
1513
1531
raise error
1514
1532
0 commit comments