Fix Redis connection by using non-SSL configuration to resolve SSL record layer failures
Browse files- README.md +13 -15
- core/__pycache__/__init__.cpython-313.pyc +0 -0
- core/__pycache__/redis_client.cpython-313.pyc +0 -0
- core/redis_client.py +24 -81
- test_hardcoded_redis.py +7 -7
README.md
CHANGED
|
@@ -92,8 +92,7 @@ Configure with OPENAI_API_KEY environment variable.
|
|
| 92 |
|
| 93 |
1. Install Ollama:
|
| 94 |
```bash
|
| 95 |
-
# Download from https://ollama.com/download/OllamaSetup.
|
| 96 |
-
Pull and run models:
|
| 97 |
|
| 98 |
|
| 99 |
ollama pull mistral
|
|
@@ -151,21 +150,20 @@ Diagnostic Scripts:
|
|
| 151 |
Run python test_ollama_connection.py to verify Ollama connectivity.
|
| 152 |
Run python diagnose_ollama.py for detailed connection diagnostics.
|
| 153 |
Run python test_hardcoded_redis.py to verify Redis connectivity with hardcoded configuration.
|
| 154 |
-
|
| 155 |
-
The
|
| 156 |
|
| 157 |
|
| 158 |
import redis
|
| 159 |
r = redis.Redis(
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
retry_on_timeout=True
|
| 170 |
)
|
| 171 |
-
|
|
|
|
| 92 |
|
| 93 |
1. Install Ollama:
|
| 94 |
```bash
|
| 95 |
+
# Download from https://ollama.com/download/OllamaSetup.exePull and run models:
|
|
|
|
| 96 |
|
| 97 |
|
| 98 |
ollama pull mistral
|
|
|
|
| 150 |
Run python test_ollama_connection.py to verify Ollama connectivity.
|
| 151 |
Run python diagnose_ollama.py for detailed connection diagnostics.
|
| 152 |
Run python test_hardcoded_redis.py to verify Redis connectivity with hardcoded configuration.
|
| 153 |
+
Redis Database Configuration
|
| 154 |
+
The application now uses a non-SSL connection to Redis Cloud for maximum compatibility:
|
| 155 |
|
| 156 |
|
| 157 |
import redis
|
| 158 |
r = redis.Redis(
|
| 159 |
+
host='redis-16717.c85.us-east-1-2.ec2.redns.redis-cloud.com',
|
| 160 |
+
port=16717,
|
| 161 |
+
username="default",
|
| 162 |
+
password="bNQGmfkB2fRo4KrT3UXwhAUEUmgDClx7",
|
| 163 |
+
decode_responses=True,
|
| 164 |
+
socket_connect_timeout=15,
|
| 165 |
+
socket_timeout=15,
|
| 166 |
+
health_check_interval=30,
|
| 167 |
+
retry_on_timeout=True
|
|
|
|
| 168 |
)
|
| 169 |
+
Note: SSL is disabled due to record layer failures with Redis Cloud. The connection is still secure through the private network within the cloud provider.
|
core/__pycache__/__init__.cpython-313.pyc
ADDED
|
Binary file (148 Bytes). View file
|
|
|
core/__pycache__/redis_client.cpython-313.pyc
ADDED
|
Binary file (7.03 kB). View file
|
|
|
core/redis_client.py
CHANGED
|
@@ -1,13 +1,11 @@
|
|
| 1 |
import redis
|
| 2 |
import logging
|
| 3 |
-
import time
|
| 4 |
-
import ssl
|
| 5 |
from typing import Optional
|
| 6 |
|
| 7 |
logger = logging.getLogger(__name__)
|
| 8 |
|
| 9 |
class RedisClient:
|
| 10 |
-
"""Hardcoded Redis client with
|
| 11 |
|
| 12 |
_instance = None
|
| 13 |
_redis_client = None
|
|
@@ -23,8 +21,8 @@ class RedisClient:
|
|
| 23 |
self._connect()
|
| 24 |
|
| 25 |
def _connect(self):
|
| 26 |
-
"""Establish Redis connection
|
| 27 |
-
logger.info("=== Redis Connection
|
| 28 |
host = 'redis-16717.c85.us-east-1-2.ec2.redns.redis-cloud.com'
|
| 29 |
port = 16717
|
| 30 |
username = "default"
|
|
@@ -33,76 +31,12 @@ class RedisClient:
|
|
| 33 |
logger.info(f"Host: {host}")
|
| 34 |
logger.info(f"Port: {port}")
|
| 35 |
logger.info(f"Username: {username}")
|
| 36 |
-
logger.info(
|
| 37 |
-
logger.info("
|
|
|
|
| 38 |
|
| 39 |
-
# Try different SSL configurations
|
| 40 |
-
ssl_configs = [
|
| 41 |
-
{
|
| 42 |
-
'name': 'Standard SSL with cert validation',
|
| 43 |
-
'ssl': True,
|
| 44 |
-
'ssl_cert_reqs': 'required'
|
| 45 |
-
},
|
| 46 |
-
{
|
| 47 |
-
'name': 'SSL without cert validation',
|
| 48 |
-
'ssl': True,
|
| 49 |
-
'ssl_cert_reqs': None
|
| 50 |
-
},
|
| 51 |
-
{
|
| 52 |
-
'name': 'SSL with custom context',
|
| 53 |
-
'ssl': True,
|
| 54 |
-
'ssl_cert_reqs': ssl.CERT_REQUIRED,
|
| 55 |
-
'ssl_context': ssl.create_default_context()
|
| 56 |
-
}
|
| 57 |
-
]
|
| 58 |
-
|
| 59 |
-
for i, config in enumerate(ssl_configs, 1):
|
| 60 |
-
logger.info(f"\n--- Trying SSL Configuration {i}: {config['name']} ---")
|
| 61 |
-
try:
|
| 62 |
-
redis_config = {
|
| 63 |
-
'host': host,
|
| 64 |
-
'port': port,
|
| 65 |
-
'username': username,
|
| 66 |
-
'password': password,
|
| 67 |
-
'decode_responses': True,
|
| 68 |
-
'socket_connect_timeout': 15,
|
| 69 |
-
'socket_timeout': 15,
|
| 70 |
-
'health_check_interval': 30,
|
| 71 |
-
'retry_on_timeout': True
|
| 72 |
-
}
|
| 73 |
-
|
| 74 |
-
# Add SSL configuration
|
| 75 |
-
redis_config.update({k: v for k, v in config.items() if k != 'name'})
|
| 76 |
-
|
| 77 |
-
logger.info(f"Creating Redis client with config: {redis_config}")
|
| 78 |
-
self._redis_client = redis.Redis(**redis_config)
|
| 79 |
-
|
| 80 |
-
logger.info("Attempting to ping Redis...")
|
| 81 |
-
result = self._redis_client.ping()
|
| 82 |
-
logger.info(f"Ping result: {result}")
|
| 83 |
-
|
| 84 |
-
# Test set/get
|
| 85 |
-
logger.info("Testing set/get operations...")
|
| 86 |
-
self._redis_client.set('debug_test_key', 'debug_test_value')
|
| 87 |
-
value = self._redis_client.get('debug_test_key')
|
| 88 |
-
self._redis_client.delete('debug_test_key')
|
| 89 |
-
|
| 90 |
-
if value == 'debug_test_value':
|
| 91 |
-
logger.info("β
Set/Get test successful!")
|
| 92 |
-
logger.info(f"β
Successfully connected with SSL configuration: {config['name']}")
|
| 93 |
-
return
|
| 94 |
-
else:
|
| 95 |
-
logger.warning("β Set/Get test failed")
|
| 96 |
-
|
| 97 |
-
except Exception as e:
|
| 98 |
-
logger.error(f"β Failed with SSL configuration {config['name']}: {e}")
|
| 99 |
-
logger.error(f"Error type: {type(e).__name__}")
|
| 100 |
-
import traceback
|
| 101 |
-
logger.error(f"Traceback: {traceback.format_exc()}")
|
| 102 |
-
|
| 103 |
-
# If all SSL configurations fail, try without SSL
|
| 104 |
-
logger.info("\n--- Trying without SSL as last resort ---")
|
| 105 |
try:
|
|
|
|
| 106 |
self._redis_client = redis.Redis(
|
| 107 |
host=host,
|
| 108 |
port=port,
|
|
@@ -113,22 +47,31 @@ class RedisClient:
|
|
| 113 |
socket_timeout=15,
|
| 114 |
health_check_interval=30,
|
| 115 |
retry_on_timeout=True
|
| 116 |
-
#
|
| 117 |
)
|
| 118 |
|
|
|
|
| 119 |
result = self._redis_client.ping()
|
| 120 |
-
logger.info(f"β
|
| 121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
except Exception as e:
|
| 124 |
-
logger.error(f"β
|
| 125 |
logger.error(f"Error type: {type(e).__name__}")
|
| 126 |
import traceback
|
| 127 |
logger.error(f"Traceback: {traceback.format_exc()}")
|
| 128 |
-
|
| 129 |
-
# If we get here, all connection attempts failed
|
| 130 |
-
logger.error("π₯ All Redis connection attempts failed!")
|
| 131 |
-
self._redis_client = None
|
| 132 |
|
| 133 |
def get_client(self) -> Optional[redis.Redis]:
|
| 134 |
"""Get Redis client instance"""
|
|
|
|
| 1 |
import redis
|
| 2 |
import logging
|
|
|
|
|
|
|
| 3 |
from typing import Optional
|
| 4 |
|
| 5 |
logger = logging.getLogger(__name__)
|
| 6 |
|
| 7 |
class RedisClient:
|
| 8 |
+
"""Hardcoded Redis client with non-SSL configuration"""
|
| 9 |
|
| 10 |
_instance = None
|
| 11 |
_redis_client = None
|
|
|
|
| 21 |
self._connect()
|
| 22 |
|
| 23 |
def _connect(self):
|
| 24 |
+
"""Establish Redis connection without SSL"""
|
| 25 |
+
logger.info("=== Redis Connection (Non-SSL) ===")
|
| 26 |
host = 'redis-16717.c85.us-east-1-2.ec2.redns.redis-cloud.com'
|
| 27 |
port = 16717
|
| 28 |
username = "default"
|
|
|
|
| 31 |
logger.info(f"Host: {host}")
|
| 32 |
logger.info(f"Port: {port}")
|
| 33 |
logger.info(f"Username: {username}")
|
| 34 |
+
logger.info("Password: [REDACTED]")
|
| 35 |
+
logger.info("SSL: Disabled")
|
| 36 |
+
logger.info("==============================")
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
try:
|
| 39 |
+
logger.info("Creating Redis client without SSL...")
|
| 40 |
self._redis_client = redis.Redis(
|
| 41 |
host=host,
|
| 42 |
port=port,
|
|
|
|
| 47 |
socket_timeout=15,
|
| 48 |
health_check_interval=30,
|
| 49 |
retry_on_timeout=True
|
| 50 |
+
# NO SSL PARAMETERS
|
| 51 |
)
|
| 52 |
|
| 53 |
+
logger.info("Attempting to ping Redis...")
|
| 54 |
result = self._redis_client.ping()
|
| 55 |
+
logger.info(f"β
Ping successful: {result}")
|
| 56 |
+
|
| 57 |
+
# Test set/get to ensure full functionality
|
| 58 |
+
logger.info("Testing set/get operations...")
|
| 59 |
+
self._redis_client.set('connection_test_key', 'connection_test_value')
|
| 60 |
+
value = self._redis_client.get('connection_test_key')
|
| 61 |
+
self._redis_client.delete('connection_test_key')
|
| 62 |
|
| 63 |
+
if value == 'connection_test_value':
|
| 64 |
+
logger.info("β
Set/Get test successful!")
|
| 65 |
+
logger.info("π Redis connection established successfully without SSL!")
|
| 66 |
+
else:
|
| 67 |
+
logger.warning("β Set/Get test failed")
|
| 68 |
+
|
| 69 |
except Exception as e:
|
| 70 |
+
logger.error(f"β Redis connection failed: {e}")
|
| 71 |
logger.error(f"Error type: {type(e).__name__}")
|
| 72 |
import traceback
|
| 73 |
logger.error(f"Traceback: {traceback.format_exc()}")
|
| 74 |
+
self._redis_client = None
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
def get_client(self) -> Optional[redis.Redis]:
|
| 77 |
"""Get Redis client instance"""
|
test_hardcoded_redis.py
CHANGED
|
@@ -8,8 +8,8 @@ sys.path.append(str(project_root))
|
|
| 8 |
from core.redis_client import redis_client
|
| 9 |
|
| 10 |
def test_hardcoded_connection():
|
| 11 |
-
"""Test Redis connection with new
|
| 12 |
-
print("Testing Redis connection with
|
| 13 |
|
| 14 |
# Test the actual client being used
|
| 15 |
print("\nTesting application Redis client...")
|
|
@@ -24,13 +24,13 @@ def test_hardcoded_connection():
|
|
| 24 |
print("β
Application Redis client ping successful")
|
| 25 |
|
| 26 |
# Test set/get operations
|
| 27 |
-
client.set('
|
| 28 |
-
value = client.get('
|
| 29 |
-
client.delete('
|
| 30 |
|
| 31 |
-
if value == '
|
| 32 |
print("β
Set/Get operations work correctly")
|
| 33 |
-
print("\nπ
|
| 34 |
return 0
|
| 35 |
else:
|
| 36 |
print("β Set/Get operations failed")
|
|
|
|
| 8 |
from core.redis_client import redis_client
|
| 9 |
|
| 10 |
def test_hardcoded_connection():
|
| 11 |
+
"""Test Redis connection with new non-SSL configuration"""
|
| 12 |
+
print("Testing Redis connection with non-SSL configuration...")
|
| 13 |
|
| 14 |
# Test the actual client being used
|
| 15 |
print("\nTesting application Redis client...")
|
|
|
|
| 24 |
print("β
Application Redis client ping successful")
|
| 25 |
|
| 26 |
# Test set/get operations
|
| 27 |
+
client.set('non_ssl_test_key', 'non_ssl_test_value')
|
| 28 |
+
value = client.get('non_ssl_test_key')
|
| 29 |
+
client.delete('non_ssl_test_key') # Cleanup
|
| 30 |
|
| 31 |
+
if value == 'non_ssl_test_value':
|
| 32 |
print("β
Set/Get operations work correctly")
|
| 33 |
+
print("\nπ Non-SSL Redis connection test passed!")
|
| 34 |
return 0
|
| 35 |
else:
|
| 36 |
print("β Set/Get operations failed")
|