19
19
20
20
from litellm import get_secret , get_secret_str
21
21
from litellm .constants import REDIS_CONNECTION_POOL_TIMEOUT , REDIS_SOCKET_TIMEOUT
22
+ from litellm .litellm_core_utils .sensitive_data_masker import SensitiveDataMasker
22
23
23
24
from ._logging import verbose_logger
24
25
@@ -309,7 +310,7 @@ def get_redis_async_client(
309
310
# Check for Redis Sentinel
310
311
if "sentinel_nodes" in redis_kwargs and "service_name" in redis_kwargs :
311
312
return _init_async_redis_sentinel (redis_kwargs )
312
-
313
+ _pretty_print_redis_config ( redis_kwargs = redis_kwargs )
313
314
return async_redis .Redis (
314
315
** redis_kwargs ,
315
316
)
@@ -331,3 +332,90 @@ def get_redis_connection_pool(**env_overrides):
331
332
return async_redis .BlockingConnectionPool (
332
333
timeout = REDIS_CONNECTION_POOL_TIMEOUT , ** redis_kwargs
333
334
)
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
+
0 commit comments