A guide to integrating Redis with NestJS using ioredis directly, with a RedisModule/RedisService pattern and a real-world caching case study.
Key takeaways
- Uses direct
ioredisinstantiation withOnModuleInit/OnModuleDestroylifecycle hooks for connection management - Implements standard
set/get/deletemethods with TTL support viaEXoption - Real-world case study: A D2C brand crashed during a sale because hero product queries overwhelmed the database. Caching product data in Redis with 30-minute TTL reduced DB queries by 90% (from hundreds of thousands to a few hundred per day).
- Demonstrates the Cache-aside Pattern: check cache first, query DB on miss, populate cache with TTL
Entities and concepts
Connections to existing knowledge
This article follows the same manual ioredis pattern as Using Redis Client in NestJS but is simpler (no repository layer or FactoryProvider). It provides the strongest real-world evidence for Redis caching impact — a 90% query reduction that prevented a full database scale-up. Contrasts with the CacheModule/CacheInterceptor approach in How to add Redis cache to a NestJS app.