Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Redis storage provider for the nestjs-throttler package (DEPRECATED)

License

Notifications You must be signed in to change notification settings

kkoomen/nestjs-throttler-storage-redis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

71bc402 · Aug 26, 2024
Apr 2, 2023
May 2, 2023
Jun 6, 2020
Jul 18, 2024
Sep 9, 2023
Jun 7, 2020
Feb 22, 2021
Jun 7, 2020
Jun 7, 2020
Jun 6, 2020
Jul 26, 2024
Jun 7, 2020
Jun 7, 2020
Jun 6, 2020
Aug 26, 2024
Jun 6, 2020
May 1, 2023
Jun 6, 2020
Jul 26, 2024
Jun 7, 2020
Jun 6, 2020
Jul 26, 2024

Repository files navigation

NestJS Throttler Redis Storage (DEPRECATED)

⚠️ The original package will be further maintained by @jmcdo29, see here, as this repository will not be maintained anymore for future development.


Tests status npm

Redis storage provider for the @nestjs/throttler package.

Installation

Yarn

  • yarn add nestjs-throttler-storage-redis ioredis

NPM

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

Usage

Basic usage:

import { ThrottlerModule, seconds } from '@nestjs/throttler';
import { ThrottlerStorageRedisService } from 'nestjs-throttler-storage-redis';
import Redis from 'ioredis';

@Module({
  imports: [
    ThrottlerModule.forRoot({
      throttlers: [{ limit: 5, ttl: seconds(60) }],

      // Below are possible options on how to configure the storage service.

      // default config (host = localhost, port = 6379)
      storage: new ThrottlerStorageRedisService(),

      // connection url
      storage: new ThrottlerStorageRedisService('redis://'),

      // redis object
      storage: new ThrottlerStorageRedisService(new Redis()),

      // redis clusters
      storage: new ThrottlerStorageRedisService(new Redis.Cluster(nodes, options)),
    }),
  ],
})
export class AppModule {}

Inject another config module and service:

import { ThrottlerModule } from '@nestjs/throttler';
import { ThrottlerStorageRedisService } from 'nestjs-throttler-storage-redis';

@Module({
  imports: [
    ThrottlerModule.forRootAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: (config: ConfigService) => ({
        throttlers: [
          {
            ttl: config.get('THROTTLE_TTL'),
            limit: config.get('THROTTLE_LIMIT'),
          },
        ],
        storage: new ThrottlerStorageRedisService(),
      }),
    }),
  ],
})
export class AppModule {}

Issues

Bugs and features related to the redis implementation are welcome in this repository.

License

NestJS Throttler Redis Storage is licensed under the MIT license.