25
25
SentinelCommands ,
26
26
list_or_args ,
27
27
)
28
- from redis .connection import ConnectionPool , SSLConnection , UnixDomainSocketConnection
28
+ from redis .connection import (
29
+ AbstractConnection ,
30
+ ConnectionPool ,
31
+ SSLConnection ,
32
+ UnixDomainSocketConnection ,
33
+ )
29
34
from redis .credentials import CredentialProvider
30
35
from redis .exceptions import (
31
36
ConnectionError ,
@@ -839,11 +844,15 @@ def clean_health_check_responses(self) -> None:
839
844
def _disconnect_raise_connect (self , conn , error ) -> None :
840
845
"""
841
846
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
844
850
"""
845
851
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
+ ):
847
856
raise error
848
857
conn .connect ()
849
858
@@ -1320,8 +1329,8 @@ def _disconnect_reset_raise(self, conn, error) -> None:
1320
1329
"""
1321
1330
Close the connection, reset watching state and
1322
1331
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.
1325
1334
"""
1326
1335
conn .disconnect ()
1327
1336
# if we were already watching a variable, the watch is no longer
@@ -1332,9 +1341,12 @@ def _disconnect_reset_raise(self, conn, error) -> None:
1332
1341
raise WatchError (
1333
1342
"A ConnectionError occurred on while watching one or more keys"
1334
1343
)
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
+ ):
1338
1350
self .reset ()
1339
1351
raise
1340
1352
@@ -1492,11 +1504,15 @@ def load_scripts(self):
1492
1504
if not exist :
1493
1505
s .sha = immediate ("SCRIPT LOAD" , s .script )
1494
1506
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 :
1496
1512
"""
1497
1513
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.
1500
1516
"""
1501
1517
conn .disconnect ()
1502
1518
# 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:
1506
1522
raise WatchError (
1507
1523
"A ConnectionError occurred on while watching one or more keys"
1508
1524
)
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
1513
1530
):
1531
+
1514
1532
self .reset ()
1515
1533
raise error
1516
1534
0 commit comments