This commit is contained in:
Jakub Miazek
2024-05-08 12:27:18 +02:00
parent 098f70a9fd
commit 918ab6c28c
5 changed files with 189 additions and 189 deletions

View File

@@ -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()

View File

@@ -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)

View File

@@ -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: