CSenshi/nestjs-redis
🛠 Modular Redis toolkit for NestJS: Client, RedLock and more
Modern, production-ready Redis integration for NestJS. Unified APIs, type-safe, and built on the official node-redis client.
NestJS Redis Toolkit is a cohesive set of utilities for Redis in NestJS applications. It provides a consistent developer experience across client connections, microservices transport (Redis Streams), throttling storage, health checks, and distributed locking.
Curious about the story behind this toolkit and how it simplifies Redis in NestJS? Read the introduction on Medium:
👉 The Missing Redis Toolkit for NestJS
@nestjs/scheduleNo download data available
No tracked packages depend on this.
Install the packages you need. For a minimal Redis client setup:
npm install @nestjs-redis/client redis
Minimal setup:
// app.module.ts
import { Module } from '@nestjs/common';
import { RedisModule } from '@nestjs-redis/client';
@Module({
imports: [
RedisModule.forRoot({
options: { url: 'redis://localhost:6379' },
}),
],
})
export class AppModule {}
// app.service.ts
import { Injectable } from '@nestjs/common';
import { InjectRedis } from '@nestjs-redis/client';
import type { RedisClientType } from 'redis';
@Injectable()
export class AppService {
constructor(@InjectRedis() private readonly redis: RedisClientType) {}
async setValue(key: string, value: string) {
await this.redis.set(key, value);
}
async getValue(key: string) {
return this.redis.get(key);
}
}
For health checks, throttling, locks, Socket.IO, or microservices transport, install the corresponding packages and see their READMEs.
Enable detailed logging across all toolkit packages by setting the REDIS_MODULE_DEBUG environment variable:
REDIS_MODULE_DEBUG=true npm start
This provides comprehensive operational logging:
[RedisModule] [Connection=<empty>]: Creating Redis client...
[RedisModule] [Connection=<empty>]: [Event=connect] Connection initiated to Redis server
[RedisModule] [Connection=<empty>]: [Event=ready] Redis client is ready to accept commands
[RedisModule] [Connection=<empty>]: Redis client connected
| Package | Node.js | NestJS | Redis |
|---|---|---|---|
@nestjs-redis/client | 18+ | 9+ | 5+ |
@nestjs-redis/lock | 18+ | 9+ | 5+ |
@nestjs-redis/schedule | 18+ | 9+ | 5+ |
@nestjs-redis/throttler-storage | 18+ | 9+ | 5+ |
@nestjs-redis/health-indicator | 18+ | 9+ | 5+ |
@nestjs-redis/socket.io-adapter | 18+ | 9+ | 5+ |
@nestjs-redis/streams-transporter | 18+ | 9+ | 5+ |
All packages support NestJS 9.x, 10.x, and 11.x.
node-redis client for long-term maintenance and compatibilityMost NestJS Redis libraries were historically built on ioredis. While ioredis remains stable, maintenance is best-effort and the Redis team recommends node-redis for new projects. node-redis is actively maintained, redesigned from the ground up, and supports new and upcoming Redis features (including Redis Stack and Redis 8 capabilities). This toolkit exists to offer first‑class NestJS integrations on top of node-redis rather than ioredis.
Reference: redis/ioredis (GitHub)
@nestjs-redis on npmContributions are welcome! Please read the contributing guide in the repository and open issues/PRs with clear context and reproduction steps.
MIT © CSenshi