AI-Life-Coach-Streamlit2 / debug_redis_connection.py
rdune71's picture
Add comprehensive Redis connection debugging and network testing scripts
6c0af85
import sys
import logging
from pathlib import Path
# Add project root to path
project_root = Path(__file__).parent
sys.path.append(str(project_root))
# Set up logging to see debug information
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
from core.redis_client import redis_client
def main():
"""Debug Redis connection issues"""
print("=== Redis Connection Debug Test ===")
# Test the connection
client = redis_client.get_client()
if client is None:
print("❌ Redis client is None - connection failed")
return 1
try:
print("Testing ping...")
result = client.ping()
print(f"βœ… Ping successful: {result}")
print("Testing set/get...")
client.set('debug_test', 'success')
value = client.get('debug_test')
client.delete('debug_test')
if value == 'success':
print("βœ… Set/Get test successful!")
print("πŸŽ‰ Redis connection is working!")
return 0
else:
print("❌ Set/Get test failed")
return 1
except Exception as e:
print(f"❌ Redis operation failed: {e}")
import traceback
print(f"Traceback: {traceback.format_exc()}")
return 1
if __name__ == "__main__":
exit_code = main()
sys.exit(exit_code)