Hardcode Redis configuration with exact working values from Redis Cloud
Browse files- core/redis_client.py +14 -42
- test_hardcoded_redis.py +45 -0
core/redis_client.py
CHANGED
|
@@ -1,14 +1,13 @@
|
|
| 1 |
import redis
|
| 2 |
import logging
|
| 3 |
import time
|
| 4 |
-
import re
|
| 5 |
from typing import Optional
|
| 6 |
-
from utils.config import config
|
| 7 |
|
| 8 |
logger = logging.getLogger(__name__)
|
| 9 |
|
| 10 |
class RedisClient:
|
| 11 |
-
"""
|
|
|
|
| 12 |
_instance = None
|
| 13 |
_redis_client = None
|
| 14 |
|
|
@@ -23,24 +22,20 @@ class RedisClient:
|
|
| 23 |
self._connect()
|
| 24 |
|
| 25 |
def _connect(self):
|
| 26 |
-
"""Establish Redis connection with
|
| 27 |
-
logger.info(
|
| 28 |
-
logger.info(
|
| 29 |
-
logger.info(
|
| 30 |
-
logger.info(
|
| 31 |
-
logger.info(
|
| 32 |
-
|
| 33 |
-
if not config.redis_host or config.redis_host == "localhost":
|
| 34 |
-
logger.info("Redis not configured, skipping connection")
|
| 35 |
-
return None
|
| 36 |
|
| 37 |
try:
|
| 38 |
-
logger.info(
|
| 39 |
self._redis_client = redis.Redis(
|
| 40 |
-
host=
|
| 41 |
-
port=
|
| 42 |
-
username=
|
| 43 |
-
password=
|
| 44 |
decode_responses=True,
|
| 45 |
socket_connect_timeout=15,
|
| 46 |
socket_timeout=15,
|
|
@@ -50,36 +45,13 @@ class RedisClient:
|
|
| 50 |
)
|
| 51 |
|
| 52 |
self._redis_client.ping()
|
| 53 |
-
logger.info("Successfully connected to Redis Cloud")
|
| 54 |
return
|
| 55 |
|
| 56 |
except Exception as e:
|
| 57 |
logger.error(f"Redis connection failed: {e}")
|
| 58 |
self._redis_client = None
|
| 59 |
|
| 60 |
-
def test_basic_connection(self):
|
| 61 |
-
"""Test basic Redis connection with known working config"""
|
| 62 |
-
try:
|
| 63 |
-
test_client = redis.Redis(
|
| 64 |
-
host='redis-10296.c245.us-east-1-3.ec2.redns.redis-cloud.com',
|
| 65 |
-
port=10296,
|
| 66 |
-
username="default",
|
| 67 |
-
password="p0ZiQGG9V4cS9NcNpeiBzaOz3YmtXcYW",
|
| 68 |
-
decode_responses=True,
|
| 69 |
-
socket_connect_timeout=10,
|
| 70 |
-
socket_timeout=10,
|
| 71 |
-
ssl=True
|
| 72 |
-
)
|
| 73 |
-
|
| 74 |
-
test_client.ping()
|
| 75 |
-
test_client.set('test_key', 'test_value')
|
| 76 |
-
result = test_client.get('test_key')
|
| 77 |
-
logger.info(f"Basic connection test successful: {result}")
|
| 78 |
-
return True
|
| 79 |
-
except Exception as e:
|
| 80 |
-
logger.error(f"Basic connection test failed: {e}")
|
| 81 |
-
return False
|
| 82 |
-
|
| 83 |
def get_client(self) -> Optional[redis.Redis]:
|
| 84 |
"""Get Redis client instance"""
|
| 85 |
return self._redis_client
|
|
|
|
| 1 |
import redis
|
| 2 |
import logging
|
| 3 |
import time
|
|
|
|
| 4 |
from typing import Optional
|
|
|
|
| 5 |
|
| 6 |
logger = logging.getLogger(__name__)
|
| 7 |
|
| 8 |
class RedisClient:
|
| 9 |
+
"""Hardcoded Redis client with proven working configuration"""
|
| 10 |
+
|
| 11 |
_instance = None
|
| 12 |
_redis_client = None
|
| 13 |
|
|
|
|
| 22 |
self._connect()
|
| 23 |
|
| 24 |
def _connect(self):
|
| 25 |
+
"""Establish Redis connection with hardcoded configuration"""
|
| 26 |
+
logger.info("Attempting Redis connection with hardcoded values")
|
| 27 |
+
logger.info(" Host: redis-10296.c245.us-east-1-3.ec2.redns.redis-cloud.com")
|
| 28 |
+
logger.info(" Port: 10296")
|
| 29 |
+
logger.info(" Username: default")
|
| 30 |
+
logger.info(" Password: [REDACTED]")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
try:
|
| 33 |
+
logger.info("Connecting to Redis Cloud with hardcoded configuration")
|
| 34 |
self._redis_client = redis.Redis(
|
| 35 |
+
host='redis-10296.c245.us-east-1-3.ec2.redns.redis-cloud.com',
|
| 36 |
+
port=10296,
|
| 37 |
+
username="default",
|
| 38 |
+
password="p0ZiQGG9V4cS9NcNpeiBzaOz3YmtXcYW",
|
| 39 |
decode_responses=True,
|
| 40 |
socket_connect_timeout=15,
|
| 41 |
socket_timeout=15,
|
|
|
|
| 45 |
)
|
| 46 |
|
| 47 |
self._redis_client.ping()
|
| 48 |
+
logger.info("Successfully connected to Redis Cloud with hardcoded configuration")
|
| 49 |
return
|
| 50 |
|
| 51 |
except Exception as e:
|
| 52 |
logger.error(f"Redis connection failed: {e}")
|
| 53 |
self._redis_client = None
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
def get_client(self) -> Optional[redis.Redis]:
|
| 56 |
"""Get Redis client instance"""
|
| 57 |
return self._redis_client
|
test_hardcoded_redis.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
|
| 4 |
+
# Add project root to path
|
| 5 |
+
project_root = Path(__file__).parent
|
| 6 |
+
sys.path.append(str(project_root))
|
| 7 |
+
|
| 8 |
+
from core.redis_client import redis_client
|
| 9 |
+
|
| 10 |
+
def test_hardcoded_connection():
|
| 11 |
+
"""Test Redis connection with hardcoded configuration"""
|
| 12 |
+
print("Testing Redis connection with hardcoded configuration...")
|
| 13 |
+
|
| 14 |
+
# Test the actual client being used
|
| 15 |
+
print("\nTesting application Redis client...")
|
| 16 |
+
client = redis_client.get_client()
|
| 17 |
+
|
| 18 |
+
if client is None:
|
| 19 |
+
print("β Application Redis client is None")
|
| 20 |
+
return 1
|
| 21 |
+
|
| 22 |
+
try:
|
| 23 |
+
client.ping()
|
| 24 |
+
print("β
Application Redis client ping successful")
|
| 25 |
+
|
| 26 |
+
# Test set/get operations
|
| 27 |
+
client.set('hardcoded_test_key', 'hardcoded_test_value')
|
| 28 |
+
value = client.get('hardcoded_test_key')
|
| 29 |
+
client.delete('hardcoded_test_key') # Cleanup
|
| 30 |
+
|
| 31 |
+
if value == 'hardcoded_test_value':
|
| 32 |
+
print("β
Set/Get operations work correctly")
|
| 33 |
+
print("\nπ Hardcoded Redis connection test passed!")
|
| 34 |
+
return 0
|
| 35 |
+
else:
|
| 36 |
+
print("β Set/Get operations failed")
|
| 37 |
+
return 1
|
| 38 |
+
|
| 39 |
+
except Exception as e:
|
| 40 |
+
print(f"β Application Redis client test failed: {e}")
|
| 41 |
+
return 1
|
| 42 |
+
|
| 43 |
+
if __name__ == "__main__":
|
| 44 |
+
exit_code = test_hardcoded_connection()
|
| 45 |
+
sys.exit(exit_code)
|