@@ -196,6 +196,7 @@ def parse_cluster_myshardid(resp, **options):
196196 "username" ,
197197 "cache" ,
198198 "cache_config" ,
199+ "maint_notifications_config" ,
199200)
200201KWARGS_DISABLED_KEYS = ("host" , "port" , "retry" )
201202
@@ -535,6 +536,7 @@ def __init__(
535536 cache_config : Optional [CacheConfig ] = None ,
536537 event_dispatcher : Optional [EventDispatcher ] = None ,
537538 policy_resolver : PolicyResolver = StaticPolicyResolver (),
539+ maint_notifications_config : Optional [MaintNotificationsConfig ] = None ,
538540 ** kwargs ,
539541 ):
540542 """
@@ -605,6 +607,13 @@ def __init__(
605607 which the nodes _think_ they are, to addresses at which a client may
606608 reach them, such as when they sit behind a proxy.
607609
610+ :param maint_notifications_config:
611+ Configures the nodes connections to support maintenance notifications - see
612+ `redis.maint_notifications.MaintNotificationsConfig` for details.
613+ Only supported with RESP3.
614+ If not provided and protocol is RESP3, the maintenance notifications
615+ will be enabled by default (logic is included in the NodesManager
616+ initialization).
608617 :**kwargs:
609618 Extra arguments that will be sent into Redis instance when created
610619 (See Official redis-py doc for supported kwargs - the only limitation
@@ -709,6 +718,7 @@ def __init__(
709718 cache = cache ,
710719 cache_config = cache_config ,
711720 event_dispatcher = self ._event_dispatcher ,
721+ maint_notifications_config = maint_notifications_config ,
712722 ** kwargs ,
713723 )
714724
@@ -1628,6 +1638,9 @@ def __init__(
16281638 cache_config : Optional [CacheConfig ] = None ,
16291639 cache_factory : Optional [CacheFactoryInterface ] = None ,
16301640 event_dispatcher : Optional [EventDispatcher ] = None ,
1641+ maint_notifications_config : Optional [
1642+ MaintNotificationsConfig
1643+ ] = MaintNotificationsConfig (),
16311644 ** kwargs ,
16321645 ):
16331646 self .nodes_cache : Dict [str , Redis ] = {}
@@ -1656,6 +1669,7 @@ def __init__(
16561669 self ._credential_provider = self .connection_kwargs .get (
16571670 "credential_provider" , None
16581671 )
1672+ self .maint_notifications_config = maint_notifications_config
16591673 self .initialize ()
16601674
16611675 def get_node (self , host = None , port = None , node_name = None ):
@@ -1803,7 +1817,10 @@ def create_redis_connections(self, nodes):
18031817 for node in nodes :
18041818 if node .redis_connection is None :
18051819 node .redis_connection = self .create_redis_node (
1806- host = node .host , port = node .port , ** self .connection_kwargs
1820+ host = node .host ,
1821+ port = node .port ,
1822+ maint_notifications_config = self .maint_notifications_config ,
1823+ ** self .connection_kwargs ,
18071824 )
18081825 connection_pools .append (node .redis_connection .connection_pool )
18091826
@@ -1813,7 +1830,12 @@ def create_redis_connections(self, nodes):
18131830 )
18141831 )
18151832
1816- def create_redis_node (self , host , port , ** kwargs ):
1833+ def create_redis_node (
1834+ self ,
1835+ host ,
1836+ port ,
1837+ ** kwargs ,
1838+ ):
18171839 # We are configuring the connection pool not to retry
18181840 # connections on lower level clients to avoid retrying
18191841 # connections to nodes that are not reachable
@@ -1827,13 +1849,8 @@ def create_redis_node(self, host, port, **kwargs):
18271849 backoff = NoBackoff (), retries = 0 , supported_errors = (ConnectionError ,)
18281850 )
18291851
1830- protocol = kwargs .get ("protocol" , None )
1831- if protocol in [3 , "3" ]:
1832- kwargs .update (
1833- {"maint_notifications_config" : MaintNotificationsConfig (enabled = False )}
1834- )
18351852 if self .from_url :
1836- # Create a redis node with a costumed connection pool
1853+ # Create a redis node with a custom connection pool
18371854 kwargs .update ({"host" : host })
18381855 kwargs .update ({"port" : port })
18391856 kwargs .update ({"cache" : self ._cache })
@@ -1891,7 +1908,10 @@ def initialize(self):
18911908 else :
18921909 # Create a new Redis connection
18931910 r = self .create_redis_node (
1894- startup_node .host , startup_node .port , ** kwargs
1911+ startup_node .host ,
1912+ startup_node .port ,
1913+ maint_notifications_config = self .maint_notifications_config ,
1914+ ** kwargs ,
18951915 )
18961916 self .startup_nodes [startup_node .name ].redis_connection = r
18971917 # Make sure cluster mode is enabled on this node
0 commit comments