MCPcopy
hub / github.com/redis/redis-py / __init__

Method __init__

redis/cluster.py:338–376  ·  view source on GitHub ↗
(
        self,
        maint_notifications_config: Optional[MaintNotificationsConfig],
        **kwargs,
    )

Source from the content-addressed store, hash-verified

336 """
337
338 def __init__(
339 self,
340 maint_notifications_config: Optional[MaintNotificationsConfig],
341 **kwargs,
342 ):
343 # Initialize maintenance notifications
344 is_protocol_supported = check_protocol_version(kwargs.get("protocol"), 3)
345
346 if (
347 maint_notifications_config
348 and maint_notifications_config.enabled
349 and not is_protocol_supported
350 ):
351 raise RedisError(
352 "Maintenance notifications handlers on connection are only supported with RESP version 3"
353 )
354 if maint_notifications_config is None and is_protocol_supported:
355 maint_notifications_config = MaintNotificationsConfig()
356
357 self.maint_notifications_config = maint_notifications_config
358
359 if self.maint_notifications_config and self.maint_notifications_config.enabled:
360 self._oss_cluster_maint_notifications_handler = (
361 OSSMaintNotificationsHandler(self, self.maint_notifications_config)
362 )
363 # Update connection kwargs for all future nodes connections
364 self._update_connection_kwargs_for_maint_notifications(
365 self._oss_cluster_maint_notifications_handler
366 )
367 # Update existing nodes connections - they are created as part of the RedisCluster constructor
368 for node in self.get_nodes():
369 if node.redis_connection is None:
370 continue
371 node.redis_connection.connection_pool.update_maint_notifications_config(
372 self.maint_notifications_config,
373 oss_cluster_maint_notifications_handler=self._oss_cluster_maint_notifications_handler,
374 )
375 else:
376 self._oss_cluster_maint_notifications_handler = None
377
378 def _update_connection_kwargs_for_maint_notifications(
379 self, oss_cluster_maint_notifications_handler: OSSMaintNotificationsHandler

Callers

nothing calls this directly

Tested by

no test coverage detected