Refactor Redis management and enhance system health callbacks

- Replaced the `RedisManager` class with a more modular `SyncRedisManager` and `AsyncRedisManager`, improving the separation of synchronous and asynchronous operations.
- Updated the `system_health.py` callbacks to utilize the new `get_sync_redis_manager` function for Redis interactions, simplifying the connection process.
- Enhanced error handling and logging in Redis status checks, providing clearer feedback on connection issues.
- Revised the setup documentation to reflect changes in Redis connection testing, ensuring clarity for users.

These updates improve the maintainability and reliability of Redis interactions within the system, aligning with best practices for modular design.
This commit is contained in:
Vasily.onl
2025-06-07 00:27:17 +08:00
parent 1466223b85
commit fe9d8e75ed
4 changed files with 344 additions and 413 deletions

View File

@@ -337,34 +337,25 @@ Create a quick test script:
```python
# test_connection.py
import os
import psycopg2
import redis
from dotenv import load_dotenv
from database.connection import DatabaseManager
# Load environment variables
from dotenv import load_dotenv
load_dotenv()
# Test PostgreSQL
try:
conn = psycopg2.connect(
host=os.getenv('POSTGRES_HOST'),
port=os.getenv('POSTGRES_PORT'),
database=os.getenv('POSTGRES_DB'),
user=os.getenv('POSTGRES_USER'),
password=os.getenv('POSTGRES_PASSWORD')
)
print("✅ PostgreSQL connection successful!")
conn.close()
except Exception as e:
print(f"❌ PostgreSQL connection failed: {e}")
# Test Database
db = DatabaseManager()
db.initialize()
if db.test_connection():
print("✅ Database connection successful!")
db.close()
# Test Redis
from database.redis_manager import get_sync_redis_manager
try:
r = redis.Redis(
host=os.getenv('REDIS_HOST'),
port=int(os.getenv('REDIS_PORT')),
password=os.getenv('REDIS_PASSWORD')
)
r.ping()
redis_manager = get_sync_redis_manager()
redis_manager.initialize()
print("✅ Redis connection successful!")
except Exception as e:
print(f"❌ Redis connection failed: {e}")