Skip to content

Commit

Permalink
fix: close redis only if its used
Browse files Browse the repository at this point in the history
  • Loading branch information
callebtc committed Jan 21, 2025
1 parent 580e414 commit 6958dc9
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions cashu/mint/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
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
from ..core.settings import settings


class RedisCache:
redis: RedisType
initialized = False
expiry = settings.mint_redis_cache_ttl

def __init__(self):
Expand All @@ -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
Expand Down Expand Up @@ -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()

0 comments on commit 6958dc9

Please sign in to comment.