@nestjs-redis/kit
v0.12.1
Published
All-in-one convenience package that re-exports every module in the NestJS Redis Toolkit
Maintainers
Readme
@nestjs-redis/kit
All-in-one package containing all NestJS Redis Toolkit modules
Features
- Single dependency with all toolkit modules re-exported
- Import everything from a single entrypoint:
@nestjs-redis/kit - First-class TypeScript types and NestJS DI patterns
- Built on the official
node-redisclient
Installation
Recommended: Install the complete toolkit
npm install @nestjs-redis/kit redisAlternative: Install individual packages
If you only need specific functionality, install individual packages:
npm install @nestjs-redis/client redisQuick Start
// app.module.ts
import { Module } from '@nestjs/common';
import { TerminusModule } from '@nestjs/terminus';
import { ThrottlerModule, seconds } from '@nestjs/throttler';
import {
InjectRedis,
RedisHealthIndicator,
RedisModule,
RedisThrottlerStorage,
RedisToken,
RedlockModule,
} from '@nestjs-redis/kit';
import type { RedisClientType } from 'redis';
@Module({
imports: [
// Client
RedisModule.forRoot({ options: { url: 'redis://localhost:6379' } }),
// Locking
RedlockModule.forRootAsync({
inject: [RedisToken()],
useFactory: (redis: RedisClientType) => ({ clients: [redis] }),
}),
// Throttling
ThrottlerModule.forRootAsync({
inject: [RedisToken()],
useFactory: (redis: RedisClientType) => ({
throttlers: [{ limit: 5, ttl: seconds(60) }],
storage: new RedisThrottlerStorage(redis),
}),
}),
// Health checks
TerminusModule,
],
providers: [RedisHealthIndicator],
})
export class AppModule {}// usage.ts
import { Injectable } from '@nestjs/common';
import { InjectRedis, Redlock } from '@nestjs-redis/kit';
import type { RedisClientType } from 'redis';
@Injectable()
export class DemoService {
constructor(@InjectRedis() private readonly redis: RedisClientType) {}
@Redlock('demo:critical', 5000)
async doCriticalWork() {
await this.redis.set('key', 'value');
}
}Links
- Root repo: CSenshi/nestjs-redis
- Issues: GitHub Issues
- Discussions: GitHub Discussions
Contributing
Please see the root contributing guidelines.
License
MIT © CSenshi
