AI-Life-Coach-Streamlit2 / test_redis_connection.py
rdune71's picture
Fix Redis connection issues with proper SSL configuration and enhanced error handling
34a92ea
import sys
import os
from pathlib import Path
# Add project root to path
project_root = Path(__file__).parent
sys.path.append(str(project_root))
from core.redis_client import redis_client
from utils.config import config
def test_redis_connection():
"""Test Redis connection with current configuration"""
print("Testing Redis connection...")
print(f"REDIS_HOST: {config.redis_host}")
print(f"REDIS_PORT: {config.redis_port}")
print(f"REDIS_USERNAME: {config.redis_username}")
print(f"REDIS_DISABLE_SSL: {config.redis_disable_ssl}")
# Initialize Redis client
client = redis_client.get_client()
if client is None:
print("❌ Redis client is None - connection failed")
return False
try:
# Test ping
result = client.ping()
print(f"βœ… Ping result: {result}")
# Test basic set/get
test_key = "redis_test_key"
test_value = "redis_test_value"
client.set(test_key, test_value)
retrieved_value = client.get(test_key)
if retrieved_value == test_value:
print("βœ… Set/Get test successful")
# Clean up
client.delete(test_key)
else:
print("❌ Set/Get test failed")
return True
except Exception as e:
print(f"❌ Redis operation failed: {e}")
return False
if __name__ == "__main__":
success = test_redis_connection()
if success:
print("\nπŸŽ‰ Redis connection test passed!")
else:
print("\nπŸ’₯ Redis connection test failed!")
sys.exit(1)