2024-01-19 03:15:48 +03:00
|
|
|
from typing import AsyncGenerator
|
|
|
|
|
2024-02-03 01:08:04 +03:00
|
|
|
import redis.asyncio as redis # type: ignore
|
2024-02-02 23:38:12 +03:00
|
|
|
from fastapi import Depends
|
|
|
|
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
|
2024-01-19 03:15:48 +03:00
|
|
|
|
|
|
|
from fastfood.config import settings
|
|
|
|
|
|
|
|
async_engine = create_async_engine(settings.DATABASE_URL_asyncpg)
|
|
|
|
async_session_maker = async_sessionmaker(
|
|
|
|
async_engine,
|
|
|
|
class_=AsyncSession,
|
|
|
|
expire_on_commit=False,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
async def get_async_session() -> AsyncGenerator[AsyncSession, None]:
|
|
|
|
async with async_session_maker() as session:
|
|
|
|
yield session
|
2024-02-02 23:38:12 +03:00
|
|
|
|
|
|
|
|
|
|
|
def get_redis_pool():
|
2024-02-05 19:13:40 +03:00
|
|
|
return redis.from_url(settings.REDIS_URL, decode_responses=False)
|
2024-02-02 23:38:12 +03:00
|
|
|
|
|
|
|
|
|
|
|
async def get_async_redis_client(
|
|
|
|
redis_pool: redis.Redis = Depends(get_redis_pool),
|
|
|
|
):
|
|
|
|
return redis_pool
|