Skip to content

Commit

Permalink
Fix Redis teardown logic based on usage (#696)
Browse files Browse the repository at this point in the history
* fix: tear down redis only if used

* fix: close redis only if its used
  • Loading branch information
callebtc authored Jan 21, 2025
1 parent ad7c6b8 commit 4e7917f
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion cashu/mint/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@


class RedisCache:
initialized = False
expiry = settings.mint_redis_cache_ttl

def __init__(self):
Expand All @@ -27,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 @@ -64,4 +66,5 @@ async def wrapper(request: Request, payload: BaseModel):
return passthrough if not settings.mint_redis_cache_enabled else decorator

async def disconnect(self):
await self.redis.close()
if self.initialized:
await self.redis.close()

0 comments on commit 4e7917f

Please sign in to comment.