performance: db/aiohttp connection pooling
This commit is contained in:
@@ -16,7 +16,7 @@ from redis.commands.search.query import Query # type: ignore
|
||||
from redis.commands.search.index_definition import IndexDefinition, IndexType # type: ignore
|
||||
from redis.commands.search.field import TextField, Field # type: ignore
|
||||
from redis.commands.json.path import Path # type: ignore
|
||||
from . import private
|
||||
import shared # Use shared Redis pool
|
||||
|
||||
logger = logging.getLogger()
|
||||
log_level = logging.getLevelName(logger.level)
|
||||
@@ -34,7 +34,8 @@ class RedisCache:
|
||||
"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.redis_client: redis.Redis = redis.Redis(password=private.REDIS_PW)
|
||||
# Use shared Redis client from connection pool
|
||||
self.redis_client: redis.Redis = shared.get_redis_async_client()
|
||||
self.notifier = notifier.DiscordNotifier()
|
||||
self.notify_warnings = False
|
||||
self.regexes: list[Pattern] = [
|
||||
@@ -51,9 +52,9 @@ class RedisCache:
|
||||
try:
|
||||
await self.redis_client.ping()
|
||||
except Exception:
|
||||
logging.debug("Redis connection lost, attempting to reconnect.")
|
||||
self.redis_client = redis.Redis(password=private.REDIS_PW)
|
||||
await self.redis_client.ping() # Test the new connection
|
||||
logging.debug("Redis connection lost, refreshing client from pool.")
|
||||
# Get fresh client from shared pool
|
||||
self.redis_client = shared.get_redis_async_client()
|
||||
|
||||
async def create_index(self) -> None:
|
||||
"""Create Index"""
|
||||
|
||||
Reference in New Issue
Block a user