Redis storage provider for the nestjs-throttler package.
yarn add nestjs-throttler nestjs-throttler-storage-redis ioredis
npm install --save nestjs-throttler nestjs-throttler-storage-redis ioredis
import { ThrottlerModule } from 'nestjs-throttler';
import * as Redis from 'ioredis';
import { ThrottlerStorageRedisService } from 'nestjs-throttler-storage-redis';
@Module({
imports: [
ThrottlerModule.forRoot({
ttl: 60,
limit: 5,
storage: new ThrottlerStorageRedisService(<Redis.Redis>client),
// storage: ThrottlerStorageRedisService.create(),
// storage: ThrottlerStorageRedisService.create(<Redis.RedisOptions>options),
}),
],
})
export class AppModule {}
import { ThrottlerModule } from 'nestjs-throttler';
import { ThrottlerStorageRedisService } from 'nestjs-throttler-storage-redis';
@Module({
imports: [
ThrottlerModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: (config: ConfigService) => ({
ttl: config.get('THROTTLE_TTL'),
limit: config.get('THROTTLE_LIMIT'),
storage: new ThrottlerStorageRedisService(<Redis.Redis>client),
// storage: ThrottlerStorageRedisService.create(),
// storage: ThrottlerStorageRedisService.create(<Redis.RedisOptions>options),
}),
}),
],
})
export class AppModule {}
Bugs and features related to the redis implementation are welcome in this repository.
For any issues related to the nestjs-throttler, please submit an issue at the nestjs-throttler repository.
NestJS Throttler Redis Storage is licensed under the MIT license.