@@ -578,6 +578,7 @@ class Connection:
578578 "socket_type" ,
579579 "redis_connect_func" ,
580580 "retry_on_timeout" ,
581+  "retry_on_error" ,
581582 "health_check_interval" ,
582583 "next_health_check" ,
583584 "last_active_at" ,
@@ -606,6 +607,7 @@ def __init__(
606607 socket_keepalive_options : Optional [Mapping [int , Union [int , bytes ]]] =  None ,
607608 socket_type : int  =  0 ,
608609 retry_on_timeout : bool  =  False ,
610+  retry_on_error : Union [list , _Sentinel ] =  SENTINEL ,
609611 encoding : str  =  "utf-8" ,
610612 encoding_errors : str  =  "strict" ,
611613 decode_responses : bool  =  False ,
@@ -631,12 +633,19 @@ def __init__(
631633 self .socket_keepalive_options  =  socket_keepalive_options  or  {}
632634 self .socket_type  =  socket_type 
633635 self .retry_on_timeout  =  retry_on_timeout 
636+  if  retry_on_error  is  SENTINEL :
637+  retry_on_error  =  []
634638 if  retry_on_timeout :
639+  retry_on_error .append (TimeoutError )
640+  self .retry_on_error  =  retry_on_error 
641+  if  retry_on_error :
635642 if  not  retry :
636643 self .retry  =  Retry (NoBackoff (), 1 )
637644 else :
638645 # deep-copy the Retry object as it is mutable 
639646 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 )
640649 else :
641650 self .retry  =  Retry (NoBackoff (), 0 )
642651 self .health_check_interval  =  health_check_interval 
@@ -1169,6 +1178,7 @@ def __init__(
11691178 encoding_errors : str  =  "strict" ,
11701179 decode_responses : bool  =  False ,
11711180 retry_on_timeout : bool  =  False ,
1181+  retry_on_error : Union [list , _Sentinel ] =  SENTINEL ,
11721182 parser_class : Type [BaseParser ] =  DefaultParser ,
11731183 socket_read_size : int  =  65536 ,
11741184 health_check_interval : float  =  0.0 ,
@@ -1190,12 +1200,18 @@ def __init__(
11901200 self .socket_timeout  =  socket_timeout 
11911201 self .socket_connect_timeout  =  socket_connect_timeout  or  socket_timeout  or  None 
11921202 self .retry_on_timeout  =  retry_on_timeout 
1203+  if  retry_on_error  is  SENTINEL :
1204+  retry_on_error  =  []
11931205 if  retry_on_timeout :
1206+  retry_on_error .append (TimeoutError )
1207+  if  retry_on_error :
11941208 if  retry  is  None :
11951209 self .retry  =  Retry (NoBackoff (), 1 )
11961210 else :
11971211 # deep-copy the Retry object as it is mutable 
11981212 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 )
11991215 else :
12001216 self .retry  =  Retry (NoBackoff (), 0 )
12011217 self .health_check_interval  =  health_check_interval 
0 commit comments