31 lines
749 B
Python
31 lines
749 B
Python
from redis.asyncio import Redis as AsyncRedis
|
|
from redis import Redis as SyncRedis
|
|
from .config import get_settings
|
|
|
|
|
|
settings = get_settings()
|
|
|
|
# Async redis client for FastAPI/Async services
|
|
redis_client = AsyncRedis(
|
|
host=settings.redis_host,
|
|
port=settings.redis_port,
|
|
db=settings.redis_db,
|
|
password=settings.redis_password,
|
|
decode_responses=True,
|
|
)
|
|
|
|
# Sync redis client for synchronous services (like auth with sync DB)
|
|
sync_redis_client = SyncRedis(
|
|
host=settings.redis_host,
|
|
port=settings.redis_port,
|
|
db=settings.redis_db,
|
|
password=settings.redis_password,
|
|
decode_responses=True,
|
|
)
|
|
|
|
def get_redis() -> AsyncRedis:
|
|
return redis_client
|
|
|
|
def get_sync_redis() -> SyncRedis:
|
|
return sync_redis_client
|