Skip to content

NestJS RedisXRedis Toolkit for NestJS

Caching, distributed locks, rate limiting, and observability — with modular plugin architecture

Why NestJS RedisX? ​

NestJS RedisX provides comprehensive Redis integration for NestJS applications. It implements well-known patterns for caching, locking, and rate limiting with a focus on correctness and developer experience.

  • Production Focused — Implements proven patterns for distributed systems
  • Type Safe — Complete TypeScript support with strict typing and IntelliSense
  • Tested — Comprehensive test suite covering core functionality
  • Documented — Detailed guides, API reference, and examples
  • Performant — Optimized for low latency Redis operations
  • Configurable — Sensible defaults with full customization options

Ecosystem Comparison ​

The NestJS ecosystem offers several Redis integration options. This table helps you understand where RedisX fits.

RedisX@nestjs/cache-manager@liaoliaots/nestjs-redis@nestjs-redis/kitioredis
TypePlugin FrameworkCache ModuleClient WrapperIntegrations BundleClient Library
Underlying Clientioredis / node-rediscache-managerioredisnode-redis—
Actively Maintained✓✓✓✓Best-effort
Infrastructure
Cluster / Sentinel✓—✓✓✓
Multiple Connections✓—✓✓Manual
Health Checks✓—✓✓Manual
Caching
Basic Cache✓✓ManualManualManual
L1 + L2 (Memory + Redis)✓————
Stampede Protection✓————
Stale-While-Revalidate✓————
Tag-based Invalidation✓————
Enterprise Patterns
Distributed Locks✓——✓Manual
Lock Auto-renewal✓————
Rate Limiting✓——~¹—
Circuit Breaker✓————
Pub/Sub Messaging✓———Manual
Session Management✓————
Leader Election (cron singletons)✓————
Request Idempotency✓————
Streams + Consumer Groups✓———Manual
Observability
Prometheus Metrics✓————
OpenTelemetry Tracing✓————

¹ Throttler storage adapter only — not standalone rate limiting with multiple algorithms

Quick Example ​

typescript
import { Module } from '@nestjs/common';
import { RedisModule } from '@nestjs-redisx/core';
import { CachePlugin } from '@nestjs-redisx/cache';

@Module({
  imports: [
    RedisModule.forRoot({
      clients: {
        host: 'localhost',
        port: 6379,
      },
      plugins: [
        new CachePlugin({
          l1: { maxSize: 1000 },
          l2: { defaultTtl: 3600 },
        }),
      ],
    }),
  ],
})
export class AppModule {}
typescript
import { Injectable } from '@nestjs/common';
import { Cached } from '@nestjs-redisx/cache';

@Injectable()
export class UserService {
  @Cached({ key: 'user:{0}', ttl: 300 })
  async getUser(id: string): Promise<User> {
    return this.userRepository.findById(id);
  }
}

Core Module ​

The foundation of NestJS RedisX providing:

  • RedisModule — NestJS module with sync/async configuration
  • RedisService — High-level wrapper for Redis operations
  • Multiple Clients — Named connections for different purposes
  • Connection Types — Single, Cluster, and Sentinel support
  • Health Monitoring — Auto-reconnection and statistics
  • Driver Abstraction — Switch between ioredis and node-redis

Learn more about Core Module

Available Plugins ​

PluginVersionDescription
Cache1.0.0Two-tier caching with SWR, stampede protection, and tag invalidation
Locks1.0.0Distributed locks with auto-renewal and retry strategies
Rate Limit1.0.0Fixed window, sliding window, and token bucket algorithms
Circuit Breaker1.6.0Distributed closed/open/half-open breaker with fallbacks
Pub/Sub1.7.0Typed publish/subscribe with @Subscribe auto-discovery
Session1.12.0Session store with device page, revocation, seat limits, and lifetime cap
Leader1.13.0Leader election: singleton crons with @LeaderOnly and automatic failover
Idempotency1.0.0Request deduplication with fingerprinting and response replay
Streams1.0.0Redis Streams with consumer groups and dead letter queues
Metrics1.0.0Prometheus metrics export with Grafana dashboards
Tracing1.0.0OpenTelemetry distributed tracing integration

Resources ​

Sponsors ​

NestJS RedisX is free and open source. If it saves your team time, consider sponsoring the project.

Released under the MIT License.