mirror of
https://github.com/grillazz/fastapi-sqlalchemy-asyncpg.git
synced 2025-11-30 13:20:40 +03:00
refactor
This commit is contained in:
@@ -7,7 +7,7 @@ router = APIRouter()
|
||||
|
||||
@router.get("/redis", status_code=status.HTTP_200_OK)
|
||||
async def redis_check(request: Request):
|
||||
_redis = await request.app.state.redis
|
||||
_redis = await request.app.redis
|
||||
_info = None
|
||||
try:
|
||||
_info = await _redis.info()
|
||||
|
||||
@@ -17,9 +17,9 @@ logger = AppLogger().get_logger()
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
async def lifespan(_app: FastAPI):
|
||||
# Load the redis connection
|
||||
app.state.redis = await get_redis()
|
||||
_app.redis = await get_redis()
|
||||
|
||||
try:
|
||||
# Initialize the cache with the redis connection
|
||||
@@ -29,7 +29,7 @@ async def lifespan(app: FastAPI):
|
||||
yield
|
||||
finally:
|
||||
# close redis connection and release the resources
|
||||
await app.state.redis.close()
|
||||
await _app.redis.close()
|
||||
|
||||
|
||||
app = FastAPI(title="Stuff And Nonsense API", version="0.6", lifespan=lifespan)
|
||||
|
||||
@@ -9,11 +9,11 @@ from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
|
||||
|
||||
|
||||
async def get_from_redis(request: Request, key: str):
|
||||
return await request.app.state.redis.get(key)
|
||||
return await request.app.redis.get(key)
|
||||
|
||||
|
||||
async def set_to_redis(request: Request, key: str, value: str, ex: int):
|
||||
return await request.app.state.redis.set(key, value, ex=ex)
|
||||
return await request.app.redis.set(key, value, ex=ex)
|
||||
|
||||
|
||||
async def verify_jwt(request: Request, token: str) -> bool:
|
||||
|
||||
Reference in New Issue
Block a user