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

Function get_cluster_client_maint_notifications

tests/test_scenario/conftest.py:337–409  ·  view source on GitHub ↗

Create Redis cluster client with maintenance notifications enabled.

(
    endpoints_config,
    protocol: int = 3,
    enable_maintenance_notifications: bool = True,
    endpoint_type: Optional[EndpointType] = None,
    enable_relaxed_timeout: bool = True,
    enable_proactive_reconnect: bool = True,
    disable_retries: bool = False,
    auth_ssl_client_certs: bool = False,
    socket_timeout: Optional[float] = None,
)

Source from the content-addressed store, hash-verified

335
336
337def get_cluster_client_maint_notifications(
338 endpoints_config,
339 protocol: int = 3,
340 enable_maintenance_notifications: bool = True,
341 endpoint_type: Optional[EndpointType] = None,
342 enable_relaxed_timeout: bool = True,
343 enable_proactive_reconnect: bool = True,
344 disable_retries: bool = False,
345 auth_ssl_client_certs: bool = False,
346 socket_timeout: Optional[float] = None,
347):
348 """Create Redis cluster client with maintenance notifications enabled."""
349 # Get credentials from the configuration
350 username = endpoints_config.get("username")
351 password = endpoints_config.get("password")
352
353 # Parse host and port from endpoints URL
354 endpoints = endpoints_config.get("endpoints", [])
355 if not endpoints:
356 raise ValueError("No endpoints found in configuration")
357
358 parsed = urlparse(endpoints[0])
359 host = parsed.hostname
360 port = parsed.port
361
362 if not host:
363 raise ValueError(f"Could not parse host from endpoint URL: {endpoints[0]}")
364
365 logging.info(f"Connecting to Redis Enterprise: {host}:{port} with user: {username}")
366
367 if disable_retries:
368 retry = Retry(NoBackoff(), 0)
369 else:
370 retry = Retry(
371 backoff=ExponentialWithJitterBackoff(base=0.01, cap=1), retries=10
372 )
373
374 tls_enabled = True if parsed.scheme == "rediss" else False
375 logging.info(f"TLS enabled: {tls_enabled}")
376
377 tls_kwargs = {"ssl": tls_enabled}
378
379 if tls_enabled:
380 # Prepare SSL certificate configuration
381 ssl_config = _prepare_ssl_certificates(auth_ssl_client_certs)
382 tls_kwargs.update(ssl_config)
383
384 # Configure maintenance notifications
385 maintenance_config = MaintNotificationsConfig(
386 enabled=enable_maintenance_notifications,
387 proactive_reconnect=enable_proactive_reconnect,
388 relaxed_timeout=RELAXED_TIMEOUT if enable_relaxed_timeout else -1,
389 endpoint_type=endpoint_type,
390 )
391
392 # Create Redis cluster client with maintenance notifications config
393 client = RedisCluster(
394 host=host,

Callers 1

setup_envMethod · 0.90

Calls 10

get_nodesMethod · 0.95
RetryClass · 0.90
NoBackoffClass · 0.90
RedisClusterClass · 0.90
updateMethod · 0.80
getMethod · 0.45
infoMethod · 0.45

Tested by

no test coverage detected