updated Postgres Service

This commit is contained in:
2025-04-01 17:30:40 +03:00
parent 6b9e9050a2
commit 4c87c4df91
18 changed files with 745 additions and 368 deletions

View File

@@ -1,7 +1,8 @@
import time
from typing import Dict, Any, Optional
from redis import Redis, ConnectionError, TimeoutError
from typing import Dict, Any
from redis import Redis, ConnectionError, TimeoutError, ConnectionPool
from Controllers.Redis.config import redis_configs
class RedisConn:
@@ -16,18 +17,16 @@ class RedisConn:
def __init__(
self,
config: Optional[Dict[str, Any]] = None,
max_retries: int = CONNECTION_RETRIES,
):
"""
Initialize Redis connection with configuration.
Args:
config: Redis connection configuration dictionary. If None, uses WagRedis config.
max_retries: Maximum number of connection attempts.
"""
self.max_retries = max_retries
self.config = config or {}
self.config = redis_configs.as_dict()
self._redis = None
self._pool = None
@@ -72,7 +71,6 @@ class RedisConn:
for attempt in range(1, self.max_retries + 1):
try:
if self._pool is None:
from redis import ConnectionPool
self._pool = ConnectionPool(**self.config)
self._redis = Redis(connection_pool=self._pool)
if self.check_connection():
@@ -101,7 +99,7 @@ class RedisConn:
return False
def set_connection(
self, host: str, password: str, port: int, db: int, **kwargs
self, **kwargs
) -> Redis:
"""
Recreate Redis connection with new parameters.
@@ -119,10 +117,10 @@ class RedisConn:
try:
# Update configuration
self.config = {
"host": host,
"password": password,
"port": port,
"db": db,
"host": redis_configs.HOST,
"password": redis_configs.PASSWORD,
"port": redis_configs.PORT,
"db": redis_configs.PORT,
"socket_timeout": kwargs.get("socket_timeout", self.DEFAULT_TIMEOUT),
"socket_connect_timeout": kwargs.get(
"socket_connect_timeout", self.DEFAULT_TIMEOUT