Files
python-repositories/python_repositories/config/redis_config.py
T
Brian Bjarke JensenandCursor 5e32787b90
Code Quality Pipeline / code-quality (pull_request) Successful in 52s
PR Title Check / check-title (pull_request) Successful in 6s
Test Python Package / test (pull_request) Successful in 1m3s
Add config and client injection with test reorganization.
Introduce typed config objects, optional adapter injection, and .env loading to simplify testing while preserving env-based defaults for production usage.

Co-authored-by: Cursor <[email protected]>
2026-07-05 21:34:14 +02:00

31 lines
692 B
Python

"""Redis connection configuration."""
from __future__ import annotations
import os
from dataclasses import dataclass
from python_utils import check_env
from python_repositories.config.dotenv_loader import load_dotenv
@dataclass(frozen=True)
class RedisConfig:
"""Configuration for connecting to Redis."""
uri: str
@classmethod
def from_env(
cls,
uri_env_var_name: str = "REDIS_URI",
*,
use_dotenv: bool = True,
) -> RedisConfig:
"""Load configuration from environment variables."""
if use_dotenv:
load_dotenv()
check_env(uri_env_var_name)
return cls(uri=str(os.getenv(uri_env_var_name)))