"""Redis-Client für TimeMaster (sync, für Kiosk-Nonce-Cache und Sessions).""" from __future__ import annotations import logging from typing import Optional log = logging.getLogger(__name__) _redis_client = None def get_redis_client(): """Gibt den Redis-Client zurück oder None wenn nicht konfiguriert/erreichbar.""" global _redis_client if _redis_client is not None: return _redis_client try: import redis as redis_lib from app.core.config import settings url = getattr(settings, "redis_url", "redis://localhost:6379/0") _redis_client = redis_lib.from_url(url, decode_responses=True, socket_connect_timeout=2) # Verbindung testen _redis_client.ping() log.info("Redis-Verbindung hergestellt: %s", url) return _redis_client except Exception as exc: log.warning("Redis nicht verfügbar: %s", exc) return None