python-dependency-injector/examples/miniapps/fastapi-redis/fastapiredis/redis.py
2024-12-08 18:53:29 +02:00

11 lines
327 B
Python

from typing import AsyncIterator
from redis.asyncio import from_url, Redis
async def init_redis_pool(host: str, password: str) -> AsyncIterator[Redis]:
session = from_url(f"redis://{host}", password=password, encoding="utf-8", decode_responses=True)
yield session
session.close()
await session.wait_closed()