MCPcopy Create free account
hub / github.com/BerriAI/litellm / build_redis_usage_cache

Function build_redis_usage_cache

litellm/proxy/proxy_server.py:5334–5350  ·  view source on GitHub ↗

Builds the proxy's coordination Redis client from resolved connection params. Cluster-mode targets (explicit `startup_nodes` or the REDIS_CLUSTER_NODES env var) get a `RedisClusterCache`, so consumers that branch on cluster mode (e.g. the v3 rate limiter) take the cluster path;

(redis_params: Mapping[str, object])

Source from the content-addressed store, hash-verified

5332
5333
5334def build_redis_usage_cache(redis_params: Mapping[str, object]) -> RedisCache:
5335 """
5336 Builds the proxy's coordination Redis client from resolved connection
5337 params. Cluster-mode targets (explicit `startup_nodes` or the
5338 REDIS_CLUSTER_NODES env var) get a `RedisClusterCache`, so consumers that
5339 branch on cluster mode (e.g. the v3 rate limiter) take the cluster path;
5340 everything else (host/url/sentinel) gets a plain `RedisCache`.
5341 """
5342 startup_nodes = redis_params.get("startup_nodes")
5343 if startup_nodes is None:
5344 env_cluster_nodes: Final = get_secret_str("REDIS_CLUSTER_NODES")
5345 if env_cluster_nodes is not None:
5346 startup_nodes = _UNTYPED_VALUE.validate_python(json.loads(env_cluster_nodes))
5347 non_node_params: Final = {key: value for key, value in redis_params.items() if key != "startup_nodes"}
5348 if startup_nodes:
5349 return RedisClusterCache(startup_nodes=startup_nodes, **non_node_params)
5350 return RedisCache(**non_node_params)
5351
5352
5353_build_redis_usage_cache: Final = build_redis_usage_cache

Calls 6

get_secret_strFunction · 0.90
RedisClusterCacheClass · 0.90
RedisCacheClass · 0.90
loadsMethod · 0.80
getMethod · 0.65
itemsMethod · 0.45

Tested by

no test coverage detected