added a session storage policy in Redis
This commit is contained in:
+6
-2
@@ -1,5 +1,5 @@
|
||||
import logging
|
||||
from collections.abc import AsyncIterator
|
||||
from collections.abc import AsyncGenerator
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
import uvicorn
|
||||
@@ -7,6 +7,7 @@ from fastapi import Depends, FastAPI
|
||||
|
||||
from app.core.config import Settings
|
||||
from app.core.database import create_db_engine, create_session_factory
|
||||
from app.core.redis import create_redis_client
|
||||
from app.core.request_capacity import acquire_request_slot, create_request_capacity
|
||||
from app.core.request_id import RequestIdMiddleware
|
||||
from app.endpoints.auth import router as auth_router
|
||||
@@ -29,10 +30,12 @@ def create_app(settings: Settings | None = None) -> FastAPI:
|
||||
configure_logging(settings)
|
||||
|
||||
engine = create_db_engine(settings)
|
||||
redis = create_redis_client(settings)
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(_: FastAPI) -> AsyncIterator[None]:
|
||||
async def lifespan(_: FastAPI) -> AsyncGenerator[None]:
|
||||
yield
|
||||
await redis.aclose()
|
||||
await engine.dispose()
|
||||
|
||||
application = FastAPI(title="Messenger", version="1.3.0", lifespan=lifespan)
|
||||
@@ -40,6 +43,7 @@ def create_app(settings: Settings | None = None) -> FastAPI:
|
||||
application.state.settings = settings
|
||||
application.state.engine = engine
|
||||
application.state.session_factory = create_session_factory(engine)
|
||||
application.state.redis = redis
|
||||
application.state.request_capacity = create_request_capacity(settings.max_in_flight)
|
||||
|
||||
application.add_middleware(RequestIdMiddleware)
|
||||
|
||||
Reference in New Issue
Block a user