Fix Redis configuration issue and enhance connection testing
Browse files- core/memory.py +6 -5
- test_redis_hf.py +27 -4
core/memory.py
CHANGED
|
@@ -20,15 +20,16 @@ def get_redis_client():
|
|
| 20 |
if not REDIS_AVAILABLE:
|
| 21 |
return None
|
| 22 |
|
| 23 |
-
# Debug print to verify secrets are loaded
|
| 24 |
-
logger.info(f"[DEBUG] Redis
|
|
|
|
| 25 |
|
| 26 |
last_exception = None
|
| 27 |
|
| 28 |
for attempt in range(config.redis_retries + 1):
|
| 29 |
try:
|
| 30 |
# Handle empty username/password gracefully
|
| 31 |
-
# Try with SSL first
|
| 32 |
redis_client = redis.Redis(
|
| 33 |
host=config.redis_host,
|
| 34 |
port=config.redis_port,
|
|
@@ -37,8 +38,8 @@ def get_redis_client():
|
|
| 37 |
decode_responses=True,
|
| 38 |
socket_connect_timeout=5,
|
| 39 |
socket_timeout=5,
|
| 40 |
-
ssl=True, # Enable TLS
|
| 41 |
-
ssl_cert_reqs=None # Skip cert verification
|
| 42 |
)
|
| 43 |
# Test the connection
|
| 44 |
redis_client.ping()
|
|
|
|
| 20 |
if not REDIS_AVAILABLE:
|
| 21 |
return None
|
| 22 |
|
| 23 |
+
# Debug print to verify secrets are loaded (separate lines to avoid formatting issues)
|
| 24 |
+
logger.info(f"[DEBUG] Redis Host = {config.redis_host}")
|
| 25 |
+
logger.info(f"[DEBUG] Redis Port = {config.redis_port}")
|
| 26 |
|
| 27 |
last_exception = None
|
| 28 |
|
| 29 |
for attempt in range(config.redis_retries + 1):
|
| 30 |
try:
|
| 31 |
# Handle empty username/password gracefully
|
| 32 |
+
# Try with SSL first (required for many cloud providers)
|
| 33 |
redis_client = redis.Redis(
|
| 34 |
host=config.redis_host,
|
| 35 |
port=config.redis_port,
|
|
|
|
| 38 |
decode_responses=True,
|
| 39 |
socket_connect_timeout=5,
|
| 40 |
socket_timeout=5,
|
| 41 |
+
ssl=True, # Enable TLS (required for Redis Cloud and many providers)
|
| 42 |
+
ssl_cert_reqs=None # Skip cert verification (commonly required)
|
| 43 |
)
|
| 44 |
# Test the connection
|
| 45 |
redis_client.ping()
|
test_redis_hf.py
CHANGED
|
@@ -7,8 +7,12 @@ username = os.getenv("REDIS_USERNAME") or None
|
|
| 7 |
password = os.getenv("REDIS_PASSWORD") or None
|
| 8 |
|
| 9 |
print("Connecting to Redis...")
|
| 10 |
-
print(f"Host: {host}
|
|
|
|
|
|
|
| 11 |
|
|
|
|
|
|
|
| 12 |
try:
|
| 13 |
r = redis.Redis(
|
| 14 |
host=host,
|
|
@@ -17,9 +21,28 @@ try:
|
|
| 17 |
password=password,
|
| 18 |
decode_responses=True,
|
| 19 |
socket_connect_timeout=5,
|
| 20 |
-
socket_timeout=5
|
|
|
|
|
|
|
| 21 |
)
|
| 22 |
result = r.ping()
|
| 23 |
-
print("✅ Ping successful:", result)
|
| 24 |
except Exception as e:
|
| 25 |
-
print("❌ Redis connection failed:", e)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
password = os.getenv("REDIS_PASSWORD") or None
|
| 8 |
|
| 9 |
print("Connecting to Redis...")
|
| 10 |
+
print(f"Host: {host}")
|
| 11 |
+
print(f"Port: {port}")
|
| 12 |
+
print(f"Username: {username}")
|
| 13 |
|
| 14 |
+
# Test with SSL first
|
| 15 |
+
print("\nTrying with SSL...")
|
| 16 |
try:
|
| 17 |
r = redis.Redis(
|
| 18 |
host=host,
|
|
|
|
| 21 |
password=password,
|
| 22 |
decode_responses=True,
|
| 23 |
socket_connect_timeout=5,
|
| 24 |
+
socket_timeout=5,
|
| 25 |
+
ssl=True,
|
| 26 |
+
ssl_cert_reqs=None
|
| 27 |
)
|
| 28 |
result = r.ping()
|
| 29 |
+
print("✅ Ping successful with SSL:", result)
|
| 30 |
except Exception as e:
|
| 31 |
+
print("❌ Redis connection failed with SSL:", e)
|
| 32 |
+
|
| 33 |
+
# Try without SSL
|
| 34 |
+
print("\nTrying without SSL...")
|
| 35 |
+
try:
|
| 36 |
+
r = redis.Redis(
|
| 37 |
+
host=host,
|
| 38 |
+
port=port,
|
| 39 |
+
username=username,
|
| 40 |
+
password=password,
|
| 41 |
+
decode_responses=True,
|
| 42 |
+
socket_connect_timeout=5,
|
| 43 |
+
socket_timeout=5
|
| 44 |
+
)
|
| 45 |
+
result = r.ping()
|
| 46 |
+
print("✅ Ping successful without SSL:", result)
|
| 47 |
+
except Exception as e2:
|
| 48 |
+
print("❌ Redis connection failed without SSL:", e2)
|