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]>
This commit is contained in:
co-authored by
Cursor
parent
366831ac52
commit
7991dabdbc
@@ -0,0 +1,30 @@
|
||||
"""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)))
|
||||
Reference in New Issue
Block a user