mirror of
https://github.com/aljazceru/nutshell.git
synced 2026-01-07 10:54:20 +01:00
Fix Redis teardown logic based on usage (#696)
* fix: tear down redis only if used * fix: close redis only if its used
This commit is contained in:
@@ -13,6 +13,7 @@ from ..core.settings import settings
|
||||
|
||||
|
||||
class RedisCache:
|
||||
initialized = False
|
||||
expiry = settings.mint_redis_cache_ttl
|
||||
|
||||
def __init__(self):
|
||||
@@ -27,6 +28,7 @@ class RedisCache:
|
||||
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
|
||||
@@ -64,4 +66,5 @@ class RedisCache:
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user