Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions litellm/_redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,18 @@ def init_redis_cluster(redis_kwargs) -> redis.RedisCluster:

def _init_redis_sentinel(redis_kwargs) -> redis.Redis:
sentinel_nodes = redis_kwargs.get("sentinel_nodes")
sentinel_password = redis_kwargs.get("sentinel_password")
service_name = redis_kwargs.get("service_name")

connection_kwargs = {}
args = _get_redis_cluster_kwargs()
for arg in redis_kwargs:
if arg in args:
connection_kwargs[arg] = redis_kwargs[arg]

# Use connection_kwargs and override special kwargs for sentinel
sentinel_kwargs = dict(connection_kwargs)
sentinel_kwargs["password"] = sentinel_password

if not sentinel_nodes or not service_name:
raise ValueError(
Expand All @@ -214,7 +225,12 @@ def _init_redis_sentinel(redis_kwargs) -> redis.Redis:
verbose_logger.debug("init_redis_sentinel: sentinel nodes are being initialized.")

# Set up the Sentinel client
sentinel = redis.Sentinel(sentinel_nodes, socket_timeout=0.1)
sentinel = redis.Sentinel(
sentinel_nodes,
socket_timeout=0.1,
sentinel_kwargs=sentinel_kwargs,
**connection_kwargs
)

# Return the master instance for the given service

Expand All @@ -225,7 +241,17 @@ def _init_async_redis_sentinel(redis_kwargs) -> async_redis.Redis:
sentinel_nodes = redis_kwargs.get("sentinel_nodes")
sentinel_password = redis_kwargs.get("sentinel_password")
service_name = redis_kwargs.get("service_name")


connection_kwargs = {}
args = _get_redis_cluster_kwargs()
for arg in redis_kwargs:
if arg in args:
connection_kwargs[arg] = redis_kwargs[arg]

# Use connection_kwargs and override special kwargs for sentinel
sentinel_kwargs = dict(connection_kwargs)
sentinel_kwargs["password"] = sentinel_password

if not sentinel_nodes or not service_name:
raise ValueError(
"Both 'sentinel_nodes' and 'service_name' are required for Redis Sentinel."
Expand All @@ -237,7 +263,8 @@ def _init_async_redis_sentinel(redis_kwargs) -> async_redis.Redis:
sentinel = async_redis.Sentinel(
sentinel_nodes,
socket_timeout=0.1,
password=sentinel_password,
sentinel_kwargs=sentinel_kwargs,
**connection_kwargs
)

# Return the master instance for the given service
Expand Down