# ！/usr/bin/python
# -*- coding: utf-8 -*-
'''
@Project    : lq-agent-api
@File       :redis_config.py
@IDE        :PyCharm
@Author     :
@Date       :2025/7/21 13:44
'''

from dataclasses import dataclass
from foundation.infrastructure.config.config import config_handler


@dataclass
class RedisConfig:
    """Redis 连接配置"""
    url: str = "redis://127.0.0.1:6379"
    host: str = "127.0.0.1"
    port: int = 6379
    password: str = None
    db: int = 0
    max_connections: int = 50
    session_prefix: str = "session:"
    lock_prefix: str = "lock:"
    session_ttl: int = 3600  # 会话过期时间(秒)



def load_config_from_env() -> tuple[RedisConfig]:
    """从环境变量加载配置"""
    redis_config = RedisConfig(
        url=config_handler.get("redis", "REDIS_URL"),
        password=config_handler.get("redis", "REDIS_PASSWORD"),
        db=int(config_handler.get("redis", "REDIS_DB", "0")),
        max_connections=int(config_handler.get("redis", "REDIS_MAX_CONNECTIONS", "50"))
    )
    return redis_config

