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