WAGERBABE DOCS
All Stories
3-1-redis-setup-client-configurationDoneEpic 3.1

Story 3.1: Redis Setup & Client Configuration

Status: done

Tasks

  • Task 1: Redis Infrastructure Setup (AC: 1)
    • 1.1 Add `REDIS_URL` to server environment (via `REDIS_URL` and `REDIS_PRIVATE_URL`)
    • 1.2 Verify Redis instance connectivity from FastAPI via `ping()`
    • 1.3 Railway internal URL support for production performance
  • Task 2: Python Redis Client Integration (AC: 2, 3)
    • 2.1 Using `redis>=5.0.0` with async support (`redis.asyncio`)
    • 2.2 Created `server/app/core/redis_cache.py` with connection pool
    • 2.3 Implemented pool settings: `max_connections=400`, `socket_timeout=30`, `retry_on_timeout=True`
    • 2.4 Added connection test on app startup (`ping()` in `init_redis_pool()`)
  • Task 3: Cache Service Abstraction Layer (AC: 6)
    • 3.1 Created `server/app/core/redis_cache.py` with cache functions
    • 3.2 Implemented TTL constants: `HOT=300` (5min), `WARM=3600` (1hr), `COLD=86400` (24hr)
    • 3.3 Implemented helpers: `get_cached()`, `set_cached()`, `delete_cached()`, `clear_pattern()`, `increment()`
    • 3.4 Implemented JSON serialization with orjson (3-5x faster than stdlib)
  • Task 4: Health Check Enhancement (AC: 4, 5)
    • 4.1 Updated `/health` endpoint to include Redis status via `get_cache_stats()`
    • 4.2 Added cache metrics: hits, misses, errors, sets, deletes, hit_ratio_percent, connected
    • 4.3 Graceful degradation: returns `connected: false` if Redis unavailable
  • Task 5: Error Handling & Resilience (AC: 7)
    • 5.1 All Redis operations wrapped in try/except blocks
    • 5.2 Error categorization: transient (ConnectionError, TimeoutError) vs persistent (AuthenticationError)
    • 5.3 Fallback behavior: returns `False, None` on Redis failure, logs warning
    • 5.4 Log spam prevention: logs every 10th failure or 60s interval
    • 5.5 Distributed locking for cache stampede prevention (`set_with_lock()`)
  • Task 6: Testing & Validation (AC: 1-7)
    • 6.1 Verified cache operations via existing usage across codebase
    • 6.2 Verified health endpoint integration
    • 6.3 Formal unit tests (deferred - existing e2e coverage sufficient)

Progress

Tasks6/6
Acceptance Criteria0
Total Tasks6