rdune71 commited on
Commit
ec5a582
Β·
1 Parent(s): 6c0af85

Fix Redis connection by using non-SSL configuration to resolve SSL record layer failures

Browse files
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.exe
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
- New Redis Database Configuration
155
- The Redis connection now uses the new database credentials:
156
 
157
 
158
  import redis
159
  r = redis.Redis(
160
- host='redis-16717.c85.us-east-1-2.ec2.redns.redis-cloud.com',
161
- port=16717,
162
- username="default",
163
- password="bNQGmfkB2fRo4KrT3UXwhAUEUmgDClx7",
164
- decode_responses=True,
165
- socket_connect_timeout=15,
166
- socket_timeout=15,
167
- ssl=True,
168
- health_check_interval=30,
169
- retry_on_timeout=True
170
  )
171
- This configuration has been tested and confirmed working.
 
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 comprehensive debugging"""
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 with comprehensive debugging"""
27
- logger.info("=== Redis Connection Debug Information ===")
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(f"Password: {'*' * len(password) if password else 'None'}")
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
- # No SSL parameters
117
  )
118
 
 
119
  result = self._redis_client.ping()
120
- logger.info(f"βœ… Non-SSL connection successful! Ping result: {result}")
121
- return
 
 
 
 
 
122
 
 
 
 
 
 
 
123
  except Exception as e:
124
- logger.error(f"❌ Non-SSL connection also failed: {e}")
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 hardcoded configuration"""
12
- print("Testing Redis connection with new hardcoded configuration...")
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('new_database_test_key', 'new_database_test_value')
28
- value = client.get('new_database_test_key')
29
- client.delete('new_database_test_key') # Cleanup
30
 
31
- if value == 'new_database_test_value':
32
  print("βœ… Set/Get operations work correctly")
33
- print("\nπŸŽ‰ New Redis database connection test passed!")
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")