mirror of
https://github.com/grillazz/fastapi-sqlalchemy-asyncpg.git
synced 2026-01-17 11:40:39 +03:00
This ensures that the Redis connection is always properly closed.
This commit is contained in:
@@ -18,9 +18,11 @@ 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()
|
||||||
yield
|
try:
|
||||||
# close redis connection and release the resources
|
yield
|
||||||
app.state.redis.close()
|
finally:
|
||||||
|
# close redis connection and release the resources
|
||||||
|
app.state.redis.close()
|
||||||
|
|
||||||
|
|
||||||
app = FastAPI(title="Stuff And Nonsense API", version="0.6", lifespan=lifespan)
|
app = FastAPI(title="Stuff And Nonsense API", version="0.6", lifespan=lifespan)
|
||||||
|
|||||||
Reference in New Issue
Block a user