Skip to content

Consolidate Redis operations with retry logic and pipeline support #42

Description

@mikevitelli

Context

Redis operations are scattered across lib/redis.ts, lib/deviceToken.ts, lib/deviceCode.ts, and lib/deviceStatus.ts. Each module calls Redis directly with no retry logic, no error recovery, and no transaction support.

Issues:

  • getUserSettings extends TTL on every read but doesn't handle expiry failure
  • setUserSettings in deviceToken.ts partially updates settings (risk of losing fields)
  • No connection error handling (Upstash outage = 500 errors everywhere)
  • TTL values (90 days) duplicated across files

Proposed approach

  1. Create lib/redis-ops.ts with typed wrappers for common patterns:
    • getWithTTLRefresh<T>(key, ttl, schema) - get + validate + refresh TTL
    • setWithTTL<T>(key, value, ttl) - set + TTL in pipeline
    • atomicUpdate<T>(key, updater) - read-modify-write in pipeline
  2. Add retry logic for transient Upstash errors (1 retry with backoff)
  3. Centralize TTL constants
  4. Use spread operator for partial settings updates to preserve all fields

Acceptance criteria

  • All Redis operations go through typed wrappers
  • Transient errors retried once before failing
  • Settings updates preserve all existing fields
  • TTL values defined in one place

Metadata

Metadata

Assignees

No one assigned

    Labels

    clouduconsole.cloudrefactorCode refactoring and cleanup

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions