File size: 1,632 Bytes
34a92ea |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
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)
|