import redis
import redis.asyncio as redis_asyncio

from app.core.config import settings

redis_client = redis.Redis.from_url(settings.redis_url, decode_responses=True)

# A separate async client, used only for the courier-tracking WebSocket
# (app.api.v1.endpoints.tracking): pub/sub there needs a non-blocking
# listen loop, which the sync client above can't do without tying up a
# whole thread per open connection. Everything else in the app stays on
# the sync client — no reason to touch a working pattern.
async_redis_client = redis_asyncio.Redis.from_url(
    settings.redis_url, decode_responses=True
)


def get_redis() -> redis.Redis:
    return redis_client


def get_async_redis() -> redis_asyncio.Redis:
    return async_redis_client
