mirror of
https://github.com/grillazz/fastapi-sqlalchemy-asyncpg.git
synced 2025-08-26 16:40:40 +03:00
This ensures that the Redis connection is always properly closed.
This commit is contained in:
parent
4d79561f8d
commit
32367d783d
@ -18,9 +18,11 @@ logger = AppLogger().get_logger()
|
||||
async def lifespan(app: FastAPI):
|
||||
# Load the redis connection
|
||||
app.state.redis = await get_redis()
|
||||
yield
|
||||
# close redis connection and release the resources
|
||||
app.state.redis.close()
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
# close redis connection and release the resources
|
||||
app.state.redis.close()
|
||||
|
||||
|
||||
app = FastAPI(title="Stuff And Nonsense API", version="0.6", lifespan=lifespan)
|
||||
|
Loading…
x
Reference in New Issue
Block a user