Skip to content

Commit 3c43b0f

Browse files
authored
add _pretty_print_redis_config (#12073)
1 parent bd0a5f7 commit 3c43b0f

File tree

2 files changed

+96
-8
lines changed

2 files changed

+96
-8
lines changed

litellm/_redis.py

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
from litellm import get_secret, get_secret_str
2121
from litellm.constants import REDIS_CONNECTION_POOL_TIMEOUT, REDIS_SOCKET_TIMEOUT
22+
from litellm.litellm_core_utils.sensitive_data_masker import SensitiveDataMasker
2223

2324
from ._logging import verbose_logger
2425

@@ -309,7 +310,7 @@ def get_redis_async_client(
309310
# Check for Redis Sentinel
310311
if "sentinel_nodes" in redis_kwargs and "service_name" in redis_kwargs:
311312
return _init_async_redis_sentinel(redis_kwargs)
312-
313+
_pretty_print_redis_config(redis_kwargs=redis_kwargs)
313314
return async_redis.Redis(
314315
**redis_kwargs,
315316
)
@@ -331,3 +332,90 @@ def get_redis_connection_pool(**env_overrides):
331332
return async_redis.BlockingConnectionPool(
332333
timeout=REDIS_CONNECTION_POOL_TIMEOUT, **redis_kwargs
333334
)
335+
336+
def _pretty_print_redis_config(redis_kwargs: dict) -> None:
337+
"""Pretty print the Redis configuration using rich with sensitive data masking"""
338+
try:
339+
import logging
340+
341+
from rich.console import Console
342+
from rich.panel import Panel
343+
from rich.table import Table
344+
from rich.text import Text
345+
if not verbose_logger.isEnabledFor(logging.DEBUG):
346+
return
347+
348+
console = Console()
349+
350+
# Initialize the sensitive data masker
351+
masker = SensitiveDataMasker()
352+
353+
# Mask sensitive data in redis_kwargs
354+
masked_redis_kwargs = masker.mask_dict(redis_kwargs)
355+
356+
# Create main panel title
357+
title = Text("Redis Configuration", style="bold blue")
358+
359+
# Create configuration table
360+
config_table = Table(
361+
title="🔧 Redis Connection Parameters",
362+
show_header=True,
363+
header_style="bold magenta",
364+
title_justify="left",
365+
)
366+
config_table.add_column("Parameter", style="cyan", no_wrap=True)
367+
config_table.add_column("Value", style="yellow")
368+
369+
# Add rows for each configuration parameter
370+
for key, value in masked_redis_kwargs.items():
371+
if value is not None:
372+
# Special handling for complex objects
373+
if isinstance(value, list):
374+
if key == "startup_nodes" and value:
375+
# Special handling for cluster nodes
376+
value_str = f"[{len(value)} cluster nodes]"
377+
elif key == "sentinel_nodes" and value:
378+
# Special handling for sentinel nodes
379+
value_str = f"[{len(value)} sentinel nodes]"
380+
else:
381+
value_str = str(value)
382+
else:
383+
value_str = str(value)
384+
385+
config_table.add_row(key, value_str)
386+
387+
# Determine connection type
388+
connection_type = "Standard Redis"
389+
if masked_redis_kwargs.get("startup_nodes"):
390+
connection_type = "Redis Cluster"
391+
elif masked_redis_kwargs.get("sentinel_nodes"):
392+
connection_type = "Redis Sentinel"
393+
elif masked_redis_kwargs.get("url"):
394+
connection_type = "Redis (URL-based)"
395+
396+
# Create connection type info
397+
info_table = Table(
398+
title="📊 Connection Info",
399+
show_header=True,
400+
header_style="bold green",
401+
title_justify="left",
402+
)
403+
info_table.add_column("Property", style="cyan", no_wrap=True)
404+
info_table.add_column("Value", style="yellow")
405+
info_table.add_row("Connection Type", connection_type)
406+
407+
# Print everything in a nice panel
408+
console.print("\n")
409+
console.print(Panel(title, border_style="blue"))
410+
console.print(info_table)
411+
console.print(config_table)
412+
console.print("\n")
413+
414+
except ImportError:
415+
# Fallback to simple logging if rich is not available
416+
masker = SensitiveDataMasker()
417+
masked_redis_kwargs = masker.mask_dict(redis_kwargs)
418+
verbose_logger.info(f"Redis configuration: {masked_redis_kwargs}")
419+
except Exception as e:
420+
verbose_logger.error(f"Error pretty printing Redis configuration: {e}")
421+

litellm/proxy/proxy_config.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
model_list:
2-
- model_name: vertex_ai/*
2+
- model_name: azure_ai/*
33
litellm_params:
4-
model: vertex_ai/*
5-
- model_name: "anthropic/*"
6-
litellm_params:
7-
model: "anthropic/*"
8-
api_key: os.environ/ANTHROPIC_API_KEY
4+
model: azure_ai/*
5+
96

107
mcp_servers:
118
deepwiki_mcp:
@@ -17,4 +14,7 @@ general_settings:
1714
store_prompts_in_spend_logs: true
1815

1916
litellm_settings:
20-
callbacks: ["langfuse", "datadog"]
17+
callbacks: ["langfuse", "datadog"]
18+
cache: True
19+
cache_params: # set cache params for redis
20+
type: redis

0 commit comments

Comments
 (0)