@@ -41,7 +41,7 @@ def _get_redis_kwargs():
4141 "retry" ,
4242 }
4343
44- include_args = [
44+ include_args = {
4545 "url" ,
4646 "redis_connect_func" ,
4747 "gcp_service_account" ,
@@ -50,9 +50,9 @@ def _get_redis_kwargs():
5050 "azure_client_id" ,
5151 "azure_tenant_id" ,
5252 "azure_client_secret" ,
53- ]
53+ }
5454
55- available_args = [ x for x in arg_spec .args if x not in exclude_args ] + include_args
55+ available_args = { x for x in arg_spec .args if x not in exclude_args } | include_args
5656
5757 return available_args
5858
@@ -84,23 +84,23 @@ def _get_redis_cluster_kwargs(client=None):
8484 # Only allow primitive arguments
8585 exclude_args = {"self" , "connection_pool" , "retry" , "host" , "port" , "startup_nodes" }
8686
87- available_args = [ x for x in arg_spec .args if x not in exclude_args ]
88- available_args . append ( "password" )
89- available_args . append ( "username" )
90- available_args . append ( "ssl" )
91- available_args . append ( "ssl_cert_reqs" )
92- available_args . append ( "ssl_check_hostname" )
93- available_args . append ( "ssl_ca_certs" )
94- available_args . append (
95- "redis_connect_func"
96- ) # Needed for sync clusters and IAM detection
97- available_args . append ( "gcp_service_account" )
98- available_args . append ( "gcp_ssl_ca_certs" )
99- available_args . append ( "azure_redis_ad_token" )
100- available_args . append ( "azure_client_id" )
101- available_args . append ( "azure_tenant_id" )
102- available_args . append ( "azure_client_secret" )
103- available_args . append ( "max_connections" )
87+ available_args = { x for x in arg_spec .args if x not in exclude_args }
88+ available_args |= {
89+ "password" ,
90+ "username" ,
91+ "ssl" ,
92+ "ssl_cert_reqs" ,
93+ "ssl_check_hostname" ,
94+ "ssl_ca_certs" ,
95+ "redis_connect_func" , # Needed for sync clusters and IAM detection
96+ "gcp_service_account" ,
97+ "gcp_ssl_ca_certs" ,
98+ "azure_redis_ad_token" ,
99+ "azure_client_id" ,
100+ "azure_tenant_id" ,
101+ "azure_client_secret" ,
102+ "max_connections" ,
103+ }
104104
105105 return available_args
106106
@@ -479,10 +479,24 @@ def init_redis_cluster(redis_kwargs) -> redis.RedisCluster:
479479 return redis .RedisCluster (startup_nodes = new_startup_nodes , ** cluster_kwargs ) # type: ignore
480480
481481
482+ def _get_redis_sentinel_connection_kwargs (redis_kwargs : dict ) -> dict :
483+ connection_kwargs = {}
484+ args = _get_redis_kwargs ()
485+ for arg in redis_kwargs :
486+ if arg in args :
487+ connection_kwargs [arg ] = redis_kwargs [arg ]
488+
489+ return connection_kwargs
490+
491+
482492def _init_redis_sentinel (redis_kwargs ) -> redis .Redis :
483493 sentinel_nodes = redis_kwargs .get ("sentinel_nodes" )
484494 sentinel_password = redis_kwargs .get ("sentinel_password" )
485495 service_name = redis_kwargs .get ("service_name" )
496+ connection_kwargs = _get_redis_sentinel_connection_kwargs (redis_kwargs )
497+ connection_kwargs .setdefault ("socket_timeout" , REDIS_SOCKET_TIMEOUT )
498+ sentinel_kwargs = dict (connection_kwargs )
499+ sentinel_kwargs ["password" ] = sentinel_password
486500
487501 if not sentinel_nodes or not service_name :
488502 raise ValueError (
@@ -494,19 +508,22 @@ def _init_redis_sentinel(redis_kwargs) -> redis.Redis:
494508 # Set up the Sentinel client
495509 sentinel = redis .Sentinel (
496510 sentinel_nodes ,
497- socket_timeout = REDIS_SOCKET_TIMEOUT ,
498- password = sentinel_password ,
511+ sentinel_kwargs = sentinel_kwargs ,
499512 )
500513
501514 # Return the master instance for the given service
502515
503- return sentinel .master_for (service_name )
516+ return sentinel .master_for (service_name , ** connection_kwargs )
504517
505518
506519def _init_async_redis_sentinel (redis_kwargs ) -> async_redis .Redis :
507520 sentinel_nodes = redis_kwargs .get ("sentinel_nodes" )
508521 sentinel_password = redis_kwargs .get ("sentinel_password" )
509522 service_name = redis_kwargs .get ("service_name" )
523+ connection_kwargs = _get_redis_sentinel_connection_kwargs (redis_kwargs )
524+ connection_kwargs .setdefault ("socket_timeout" , REDIS_SOCKET_TIMEOUT )
525+ sentinel_kwargs = dict (connection_kwargs )
526+ sentinel_kwargs ["password" ] = sentinel_password
510527
511528 if not sentinel_nodes or not service_name :
512529 raise ValueError (
@@ -518,13 +535,12 @@ def _init_async_redis_sentinel(redis_kwargs) -> async_redis.Redis:
518535 # Set up the Sentinel client
519536 sentinel = async_redis .Sentinel (
520537 sentinel_nodes ,
521- socket_timeout = REDIS_SOCKET_TIMEOUT ,
522- password = sentinel_password ,
538+ sentinel_kwargs = sentinel_kwargs ,
523539 )
524540
525541 # Return the master instance for the given service
526542
527- return sentinel .master_for (service_name )
543+ return sentinel .master_for (service_name , ** connection_kwargs )
528544
529545
530546def get_redis_client (** env_overrides ):
0 commit comments