fix(redis): gepoolten async-Redis-Client statt Connect/Close pro Request
Security Audit / Python Dependency Audit (push) Canceled after 0s
Security Audit / Node.js Dependency Audit (push) Canceled after 0s

TOTP-Login und Kiosk-Nonce-Check öffneten/schlossen bisher pro Request eine
neue aioredis-Verbindung. Neuer get_async_redis()-Pool in core/redis.py wird
von beiden Stellen genutzt, sauberer Shutdown im FastAPI-Lifespan.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015Ahyx6D3r7G1EuAc42nezn
This commit is contained in:
2026-09-02 22:29:08 +02:00
co-authored by Claude Sonnet 5
parent 52ecd9e5ce
commit c733ddfe40
5 changed files with 50 additions and 21 deletions
+2 -3
View File
@@ -68,12 +68,11 @@ async def _check_and_set_nonce(nonce: str) -> bool:
Replay im Fallback-Fenster → Redis sollte in Production HA sein.
"""
try:
import redis.asyncio as aioredis
r: Any = aioredis.from_url(settings.redis_url, decode_responses=True)
from app.core.redis import get_async_redis
r: Any = get_async_redis()
key = f"kiosk:nonce:{nonce}"
# SETNX: setzt nur wenn nicht vorhanden, gibt 1 zurück wenn gesetzt
result = await r.set(key, "1", ex=_NONCE_TTL, nx=True)
await r.aclose()
return result is not None # None = bereits vorhanden
except Exception as e:
logger.warning("Redis nicht erreichbar, nutze In-Memory-Nonce-Cache (Lock-geschützt): %s", e)