Modular Redis toolkit for NestJS with plugin architecture
Documentation • Getting Started • API Reference • Discussions
cache-manager with production-grade L1+L2 caching, stampede protection, and tag invalidationNode.js support: the published packages run on (declared in each package's and exercised in CI on 18/20/22/24). The root of this monorepo requires - that constraint applies only to (build tooling), not to using the packages.
No download data available
No tracked packages depend on this.
enginespackage.json| Feature | What you get | |
|---|---|---|
| Cache | Two-Tier Cache | L1 memory + L2 Redis with anti-stampede, SWR, and tag invalidation |
| Locks | Distributed Locks | Redis-based locking with auto-renewal and retry strategies |
| Rate Limit | Rate Limiting | Fixed window, sliding window, and token bucket algorithms |
| Circuit Breaker | Distributed Circuit Breaker | Closed/open/half-open breaker with fail-fast rejection and fallbacks |
| Pub/Sub | Typed Pub/Sub | Publish/subscribe with pattern subscriptions and @Subscribe auto-discovery |
| Session | Session Management | express-session/@fastify/session store with device page, revoke-everywhere, seat limits |
| Leader | Leader Election | Run cron/singleton work on exactly one instance - @LeaderOnly, lease heartbeats, automatic failover |
| Semaphore | Bounded Concurrency | At most N concurrent executions fleet-wide - permit leases, auto-renewal, @WithSemaphore |
| Dedup | Deduplication / Debounce | Run webhooks and events once per window across instances - @Dedupe, distributed trailing debounce |
| Counters | Atomic Counters | Fleet-wide counters, window TTLs, atomic read-and-reset, monotonic sequences |
| Idempotency | Request Idempotency | Deduplication with fingerprinting and response replay |
| Streams | Redis Streams | Consumer groups, dead-letter queues, and backpressure |
| Metrics | Prometheus Metrics | Command latencies, cache hit rates, and custom metrics |
| Tracing | OpenTelemetry Tracing | Distributed tracing with Jaeger/Zipkin/OTLP export |
npm install @nestjs-redisx/core @nestjs-redisx/cache ioredis
import { RedisModule } from '@nestjs-redisx/core';
import { CachePlugin, Cached } from '@nestjs-redisx/cache';
import { ConfigModule, ConfigService } from '@nestjs/config';
// 1. Register
@Module({
imports: [
RedisModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
plugins: [
CachePlugin.registerAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: (config: ConfigService) => ({
l1: { maxSize: config.get('CACHE_L1_MAX_SIZE', 1000) },
l2: { defaultTtl: config.get('CACHE_L2_TTL', 3600) },
}),
}),
],
useFactory: (config: ConfigService) => ({
clients: {
host: config.get('REDIS_HOST', 'localhost'),
port: config.get('REDIS_PORT', 6379),
},
}),
}),
],
})
export class AppModule {}
// 2. Use
@Injectable()
export class UserService {
@Cached({ key: 'user:{0}', ttl: 300, tags: ['users'] })
async getUser(id: string) { return this.repo.findById(id); }
}
| Plugin | Description | Version |
|---|---|---|
| @nestjs-redisx/core | Driver abstraction, plugin system, multi-client support | |
| @nestjs-redisx/cache | L1+L2 caching with SWR, stampede protection, tags | |
| @nestjs-redisx/locks | Distributed locks with auto-renewal | |
| @nestjs-redisx/rate-limit | Multi-algorithm rate limiting | |
| @nestjs-redisx/circuit-breaker | Distributed circuit breaker (closed/open/half-open) | |
| @nestjs-redisx/pubsub | Typed Pub/Sub with @Subscribe auto-discovery | |
| @nestjs-redisx/session | Session store + device page, revocation, seat limits, lifetime cap | |
| @nestjs-redisx/leader | Leader election: singleton crons, @LeaderOnly, automatic failover | |
| @nestjs-redisx/semaphore | Distributed counting semaphore: N concurrent fleet-wide, permit leases | |
| @nestjs-redisx/dedup | Event deduplication and distributed debounce with TTL windows | |
| @nestjs-redisx/counters | Atomic counters, window counters, and monotonic sequences | |
| @nestjs-redisx/idempotency | Request deduplication and response replay | |
| @nestjs-redisx/streams | Redis Streams with consumer groups and DLQ | |
| @nestjs-redisx/metrics | Prometheus metrics for Redis operations | |
| @nestjs-redisx/tracing | OpenTelemetry distributed tracing | |
| @nestjs-redisx/testing | In-memory Redis driver for unit tests (no Redis required) |
| RedisX | @nestjs/cache-manager | @liaoliaots/nestjs-redis | ioredis | |
|---|---|---|---|---|
| L1+L2 Cache | Yes | - | - | - |
| Stampede Protection | Yes | - | - | - |
| SWR + Tag Invalidation | Yes | - | - | - |
| Distributed Locks | Yes | - | - | Manual |
| Rate Limiting | Yes | - | - | - |
| Circuit Breaker | Yes | - | - | - |
| Pub/Sub | Yes | - | - | Manual |
| Session Management | Yes | - | - | - |
| Leader Election | Yes | - | - | - |
| Distributed Semaphore | Yes | - | - | - |
| Deduplication / Debounce | Yes | - | - | Manual |
| Atomic Counters & Sequences | Yes | - | - | Manual |
| Idempotency | Yes | - | - | - |
| Streams + Consumer Groups | Yes | - | - | Manual |
| Prometheus + OTel | Yes | - | - | - |
| In-memory Test Driver (no Redis) | Yes | - | - | - |
Full documentation, guides, and API reference at nestjs-redisx.dev.
NestJS RedisX is free and open source. Development is supported by the community.
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
For better code generation with AI tools (Cursor, Claude Code, GitHub Copilot, etc.), point your agent to the full API reference:
https://nestjs-redisx.dev/llms-full.txt