ioredis adapter wraps an ioredis client to provide persistent caching with Redis.
Installation
Basic Usage
Configuration
Redis Connection
Adapter Options
With Schema Serialization
Use Effect’sSchema for type-safe serialization:
Key Storage Format
Keys are stored in Redis as:TTL Handling
Redis TTL is set tottl + swr to ensure stale data is available during the SWR window:
Invalidation
Invalidating a key removes it from both memory and Redis:Tiered Caching
Combine memory (L1) and Redis (L2) for faster reads:- Check L1 (memory) - fastest
- If miss, check L2 (Redis)
- On write, update both L1 and L2
Complete Example
Type Signature
Error Handling
Redis errors are converted to Effect failures:The
ioredis adapter converts all Redis operations to Effect and uses Effect.orDie - errors will crash the fiber unless caught with Effect.catchAll or Effect.either.