From 6958dc916663a1c0e66b34fa6f5fdd974f6c38cb Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Tue, 21 Jan 2025 17:12:48 -0600 Subject: [PATCH] fix: close redis only if its used --- cashu/mint/cache.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cashu/mint/cache.py b/cashu/mint/cache.py index d51448c2..023ce3e9 100644 --- a/cashu/mint/cache.py +++ b/cashu/mint/cache.py @@ -6,7 +6,6 @@ from loguru import logger from pydantic import BaseModel from redis.asyncio import from_url -from redis.asyncio.client import Redis as RedisType from redis.exceptions import ConnectionError from ..core.errors import CashuError @@ -14,7 +13,7 @@ class RedisCache: - redis: RedisType + initialized = False expiry = settings.mint_redis_cache_ttl def __init__(self): @@ -29,6 +28,7 @@ async def test_connection(self): try: await self.redis.ping() logger.success("Connected to Redis caching server.") + self.initialized = True except ConnectionError as e: logger.error("Redis connection error.") raise e @@ -66,5 +66,5 @@ async def wrapper(request: Request, payload: BaseModel): return passthrough if not settings.mint_redis_cache_enabled else decorator async def disconnect(self): - if self.redis: + if self.initialized: await self.redis.close()