mirror of
https://github.com/long2ice/fastapi-cache.git
synced 2026-03-24 20:47:54 +00:00
Replace aioredis with redis-py
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
from datetime import date, datetime
|
||||
|
||||
import aioredis
|
||||
import redis.asyncio as redis
|
||||
import uvicorn
|
||||
from fastapi import FastAPI
|
||||
from redis.asyncio.connection import ConnectionPool
|
||||
from starlette.requests import Request
|
||||
from starlette.responses import Response
|
||||
|
||||
@@ -47,8 +48,9 @@ async def get_datetime(request: Request, response: Response):
|
||||
|
||||
@app.on_event("startup")
|
||||
async def startup():
|
||||
redis = aioredis.from_url(url="redis://localhost")
|
||||
FastAPICache.init(RedisBackend(redis), prefix="fastapi-cache")
|
||||
pool = ConnectionPool.from_url(url="redis://localhost")
|
||||
r = redis.Redis(connection_pool=pool)
|
||||
FastAPICache.init(RedisBackend(r), prefix="fastapi-cache")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user