pythonfastapiuvicornuvloopaioredis

aioredis under uvicorn with uvloop question


I have a question. If I use aioredis together with FastAPI using uvicorn and set uvloop in the --loop argument, will aioredis use uvloop or pure asyncio?

from fastapi import FastAPI
app = FastAPI()


@app.get('/get/{key}')
async def get_from_redis(key):
    redis = aioredis.from_url('redis://127.0.0.1')
    value = await redis.get(key)  # uses uvloop or pure asyncio?
    return {'response': value}
uvicorn main:app --workers 2 --loop uvloop

Solution

  • It will use uvloop.

    Uvicorn runs asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) before starting the application.