Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

add config for setting up redis cluster

Ishaan Jaff3bf2c06e066b
diff --git a/docs/my-website/docs/proxy/caching.md b/docs/my-website/docs/proxy/caching.md
index 6324f424319..220ef5c3605 100644
--- a/docs/my-website/docs/proxy/caching.md
+++ b/docs/my-website/docs/proxy/caching.md
@@ -54,6 +54,10 @@ litellm_caching:<hash>
#### Redis Cluster
+<Tabs>
+
+<TabItem value="redis-cluster-config" label="Set on config.yaml">
+
```yaml
model_list:
- model_name: "*"
@@ -68,6 +72,44 @@ litellm_settings:
redis_startup_nodes: [{"host": "127.0.0.1", "port": "7001"}]
```
+</TabItem>
+
+<TabItem value="redis-env" label="Set on .env">
+
+You can configure redis cluster in your .env by setting `REDIS_CLUSTER_NODES` in your .env
+
+**Example `REDIS_CLUSTER_NODES`** value
+
+```
+REDIS_CLUSTER_NODES = "[{"host": "127.0.0.1", "port": "7001"}, {"host": "127.0.0.1", "port": "7003"}, {"host": "127.0.0.1", "port": "7004"}, {"host": "127.0.0.1", "port": "7005"}, {"host": "127.0.0.1", "port": "7006"}, {"host": "127.0.0.1", "port": "7007"}]"
+```
+
+:::note
+
+Example python script for setting redis cluster nodes in .env:
+
+```python
+# List of startup nodes
+startup_nodes = [
+ {"host": "127.0.0.1", "port": "7001"},
+ {"host": "127.0.0.1", "port": "7003"},
+ {"host": "127.0.0.1", "port": "7004"},
+ {"host": "127.0.0.1", "port": "7005"},
+ {"host": "127.0.0.1", "port": "7006"},
+ {"host": "127.0.0.1", "port": "7007"},
+]
+
+# set startup nodes in environment variables
+os.environ["REDIS_CLUSTER_NODES"] = json.dumps(startup_nodes)
+print("REDIS_CLUSTER_NODES", os.environ["REDIS_CLUSTER_NODES"])
+```
+
+:::
+
+</TabItem>
+
+</Tabs>
+
#### TTL
```yaml
diff --git a/litellm/tests/test_caching.py b/litellm/tests/test_caching.py
index a82d7bc8e8c..a52f17847a1 100644
--- a/litellm/tests/test_caching.py
+++ b/litellm/tests/test_caching.py
@@ -838,6 +838,7 @@ async def test_redis_cache_cluster_init_unit_test():
@pytest.mark.asyncio
[email protected](reason="Local test. Requires running redis cluster locally.")
async def test_redis_cache_cluster_init_with_env_vars_unit_test():
try:
import json
@@ -861,6 +862,7 @@ async def test_redis_cache_cluster_init_with_env_vars_unit_test():
# set startup nodes in environment variables
os.environ["REDIS_CLUSTER_NODES"] = json.dumps(startup_nodes)
+ print("REDIS_CLUSTER_NODES", os.environ["REDIS_CLUSTER_NODES"])
# unser REDIS_HOST, REDIS_PORT, REDIS_PASSWORD
os.environ.pop("REDIS_HOST", None)