This ensures that the Redis connection is always properly closed.

This commit is contained in:
Jakub Miazek 2023-11-09 21:32:01 +01:00
parent 4d79561f8d
commit 32367d783d

View File

@ -18,7 +18,9 @@ logger = AppLogger().get_logger()
async def lifespan(app: FastAPI): async def lifespan(app: FastAPI):
# Load the redis connection # Load the redis connection
app.state.redis = await get_redis() app.state.redis = await get_redis()
try:
yield yield
finally:
# close redis connection and release the resources # close redis connection and release the resources
app.state.redis.close() app.state.redis.close()