@@ -578,6 +578,7 @@ class Connection:
578
578
"socket_type" ,
579
579
"redis_connect_func" ,
580
580
"retry_on_timeout" ,
581
+ "retry_on_error" ,
581
582
"health_check_interval" ,
582
583
"next_health_check" ,
583
584
"last_active_at" ,
@@ -606,6 +607,7 @@ def __init__(
606
607
socket_keepalive_options : Optional [Mapping [int , Union [int , bytes ]]] = None ,
607
608
socket_type : int = 0 ,
608
609
retry_on_timeout : bool = False ,
610
+ retry_on_error : Union [list , _Sentinel ] = SENTINEL ,
609
611
encoding : str = "utf-8" ,
610
612
encoding_errors : str = "strict" ,
611
613
decode_responses : bool = False ,
@@ -631,12 +633,19 @@ def __init__(
631
633
self .socket_keepalive_options = socket_keepalive_options or {}
632
634
self .socket_type = socket_type
633
635
self .retry_on_timeout = retry_on_timeout
636
+ if retry_on_error is SENTINEL :
637
+ retry_on_error = []
634
638
if retry_on_timeout :
639
+ retry_on_error .append (TimeoutError )
640
+ self .retry_on_error = retry_on_error
641
+ if retry_on_error :
635
642
if not retry :
636
643
self .retry = Retry (NoBackoff (), 1 )
637
644
else :
638
645
# deep-copy the Retry object as it is mutable
639
646
self .retry = copy .deepcopy (retry )
647
+ # Update the retry's supported errors with the specified errors
648
+ self .retry .update_supported_errors (retry_on_error )
640
649
else :
641
650
self .retry = Retry (NoBackoff (), 0 )
642
651
self .health_check_interval = health_check_interval
@@ -1169,6 +1178,7 @@ def __init__(
1169
1178
encoding_errors : str = "strict" ,
1170
1179
decode_responses : bool = False ,
1171
1180
retry_on_timeout : bool = False ,
1181
+ retry_on_error : Union [list , _Sentinel ] = SENTINEL ,
1172
1182
parser_class : Type [BaseParser ] = DefaultParser ,
1173
1183
socket_read_size : int = 65536 ,
1174
1184
health_check_interval : float = 0.0 ,
@@ -1190,12 +1200,18 @@ def __init__(
1190
1200
self .socket_timeout = socket_timeout
1191
1201
self .socket_connect_timeout = socket_connect_timeout or socket_timeout or None
1192
1202
self .retry_on_timeout = retry_on_timeout
1203
+ if retry_on_error is SENTINEL :
1204
+ retry_on_error = []
1193
1205
if retry_on_timeout :
1206
+ retry_on_error .append (TimeoutError )
1207
+ if retry_on_error :
1194
1208
if retry is None :
1195
1209
self .retry = Retry (NoBackoff (), 1 )
1196
1210
else :
1197
1211
# deep-copy the Retry object as it is mutable
1198
1212
self .retry = copy .deepcopy (retry )
1213
+ # Update the retry's supported errors with the specified errors
1214
+ self .retry .update_supported_errors (retry_on_error )
1199
1215
else :
1200
1216
self .retry = Retry (NoBackoff (), 0 )
1201
1217
self .health_check_interval = health_check_interval
0 commit comments