Skip to content

Harden Redis cache adapter example for production use #426

Description

@Lakes41

Difficulty: Intermediate
Type: Feature
Recommended labels (if available in this repo): enhancement, caching, sdk

Background

examples/redis-cache-adapter/src/index.ts demonstrates plugging Redis into the SDK's cache interface, but as an example it likely omits production-readiness concerns like connection retry and failure isolation.

Problem

Consumers copying the example as a starting point for production use would inherit a Redis adapter that can crash or hang the whole app if Redis becomes temporarily unavailable, since caching should be a performance optimization, not a hard dependency.

Expected Outcome

The Redis adapter example gracefully degrades to cache-miss behavior (falling through to the origin call) when Redis is unreachable, with automatic reconnection and no unhandled promise rejections.

Suggested Implementation

Wrap Redis client calls in try/catch that treats connection errors as cache misses rather than throwing. Add reconnect-with-backoff logic (or rely on the Redis client library's built-in reconnection if available) and add a circuit-breaker-style short-circuit so repeated failures don't add per-request latency while Redis is down.

Acceptance Criteria

  • Redis being unreachable at startup does not crash the consuming app — cache adapter falls back to pass-through behavior
  • Redis becoming unreachable mid-run degrades to cache-miss behavior without throwing
  • Existing examples/redis-cache-adapter/src/index.test.ts extended to cover the failure-fallback path
  • README in examples/redis-cache-adapter/ updated to describe the fallback behavior
  • pnpm test:run passes

Likely Affected Files/Directories

  • examples/redis-cache-adapter/src/index.ts
  • examples/redis-cache-adapter/src/index.test.ts
  • examples/redis-cache-adapter/README.md

Metadata

Metadata

Assignees

No one assigned

    Labels

    GrantFox OSSGrantFox Open Source Sponsorship program tagMaybe RewardedIssue may qualify for a reward upon successful completion per campaign rulesOfficial Campaign | FWC26Official FWC26 campaign issue — eligible for campaign scoring and rewards

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions