forked from mtusi2026/mtusi2026lab5
25 lines
852 B
Python
25 lines
852 B
Python
from redis.asyncio import BlockingConnectionPool, Redis
|
|
from redis.asyncio.retry import Retry
|
|
from redis.backoff import NoBackoff
|
|
|
|
from app.core.config import Settings
|
|
|
|
|
|
def create_redis_client(settings: Settings) -> Redis:
|
|
password = (
|
|
settings.redis_password.get_secret_value() if settings.redis_password else None
|
|
)
|
|
pool = BlockingConnectionPool(
|
|
host=settings.redis_host,
|
|
port=settings.redis_port,
|
|
db=settings.redis_db,
|
|
password=password,
|
|
max_connections=settings.redis_max_connections,
|
|
timeout=settings.redis_pool_timeout_seconds,
|
|
socket_connect_timeout=settings.redis_connect_timeout_seconds,
|
|
socket_timeout=settings.redis_socket_timeout_seconds,
|
|
retry=Retry(NoBackoff(), retries=1),
|
|
decode_responses=True,
|
|
)
|
|
return Redis.from_pool(pool)
|