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 MaintainedBest-effort
Infrastructure
Cluster / Sentinel
Multiple ConnectionsManual
Health ChecksManual
Caching
Basic CacheManualManualManual
L1 + L2 (Memory + Redis)
Stampede Protection
Stale-While-Revalidate
Tag-based Invalidation
Enterprise Patterns
Distributed LocksManual
Lock Auto-renewal
Rate Limiting
Request Idempotency
Streams + Consumer GroupsManual
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
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.