/nestjs-throttler-storage-redis

Redis storage provider for the nestjs-throttler package.

Primary LanguageTypeScriptMIT LicenseMIT

NestJS Throttler Redis Storage

Redis storage provider for the nestjs-throttler package.

Installation

Yarn

  • yarn add nestjs-throttler nestjs-throttler-storage-redis ioredis

NPM

  • npm install --save nestjs-throttler nestjs-throttler-storage-redis ioredis

Usage

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 {}

Issues

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.

License

NestJS Throttler Redis Storage is licensed under the MIT license.