19
19
SentinelCommands ,
20
20
list_or_args ,
21
21
)
22
- from redis .connection import ConnectionPool , SSLConnection , UnixDomainSocketConnection
22
+ from redis .connection import (
23
+ ConnectionPool ,
24
+ SSLConnection ,
25
+ UnixDomainSocketConnection ,
26
+ AbstractConnection ,
27
+ )
23
28
from redis .credentials import CredentialProvider
24
29
from redis .exceptions import (
25
30
ConnectionError ,
@@ -781,11 +786,15 @@ def clean_health_check_responses(self) -> None:
781
786
def _disconnect_raise_connect (self , conn , error ) -> None :
782
787
"""
783
788
Close the connection and raise an exception
784
- if retry_on_timeout is not set or the error
785
- is not a TimeoutError. Otherwise, try to reconnect
789
+ if retry_on_error is not set or the error is not one
790
+ of the specified error types. Otherwise, try to
791
+ reconnect
786
792
"""
787
793
conn .disconnect ()
788
- if not (conn .retry_on_timeout and isinstance (error , TimeoutError )):
794
+ if (
795
+ conn .retry_on_error is None
796
+ or isinstance (error , tuple (conn .retry_on_error )) is False
797
+ ):
789
798
raise error
790
799
conn .connect ()
791
800
@@ -1261,8 +1270,8 @@ def _disconnect_reset_raise(self, conn, error) -> None:
1261
1270
"""
1262
1271
Close the connection, reset watching state and
1263
1272
raise an exception if we were watching,
1264
- retry_on_timeout is not set,
1265
- or the error is not a TimeoutError
1273
+ if retry_on_error is not set or the error is not one
1274
+ of the specified error types.
1266
1275
"""
1267
1276
conn .disconnect ()
1268
1277
# if we were already watching a variable, the watch is no longer
@@ -1273,9 +1282,12 @@ def _disconnect_reset_raise(self, conn, error) -> None:
1273
1282
raise WatchError (
1274
1283
"A ConnectionError occurred on while watching one or more keys"
1275
1284
)
1276
- # if retry_on_timeout is not set, or the error is not
1277
- # a TimeoutError, raise it
1278
- if not (conn .retry_on_timeout and isinstance (error , TimeoutError )):
1285
+ # if retry_on_error is not set or the error is not one
1286
+ # of the specified error types, raise it
1287
+ if (
1288
+ conn .retry_on_error is None
1289
+ or isinstance (error , tuple (conn .retry_on_error )) is False
1290
+ ):
1279
1291
self .reset ()
1280
1292
raise
1281
1293
@@ -1433,11 +1445,15 @@ def load_scripts(self):
1433
1445
if not exist :
1434
1446
s .sha = immediate ("SCRIPT LOAD" , s .script )
1435
1447
1436
- def _disconnect_raise_reset (self , conn : Redis , error : Exception ) -> None :
1448
+ def _disconnect_raise_reset (
1449
+ self ,
1450
+ conn : AbstractConnection ,
1451
+ error : Exception ,
1452
+ ) -> None :
1437
1453
"""
1438
1454
Close the connection, raise an exception if we were watching,
1439
- and raise an exception if TimeoutError is not part of retry_on_error,
1440
- or the error is not a TimeoutError
1455
+ and raise an exception if retry_on_error is not set or the
1456
+ error is not one of the specified error types.
1441
1457
"""
1442
1458
conn .disconnect ()
1443
1459
# if we were watching a variable, the watch is no longer valid
@@ -1447,11 +1463,13 @@ def _disconnect_raise_reset(self, conn: Redis, error: Exception) -> None:
1447
1463
raise WatchError (
1448
1464
"A ConnectionError occurred on while watching one or more keys"
1449
1465
)
1450
- # if TimeoutError is not part of retry_on_error, or the error
1451
- # is not a TimeoutError, raise it
1452
- if not (
1453
- TimeoutError in conn .retry_on_error and isinstance (error , TimeoutError )
1466
+ # if retry_on_error is not set or the error is not one
1467
+ # of the specified error types, raise it
1468
+ if (
1469
+ conn .retry_on_error is None
1470
+ or isinstance (error , tuple (conn .retry_on_error )) is False
1454
1471
):
1472
+
1455
1473
self .reset ()
1456
1474
raise error
1457
1475
0 commit comments