0.4.4 • Published 2 months ago

nestjs-throttler-storage-redis v0.4.4

Weekly downloads
151
License
MIT
Repository
github
Last release
2 months ago

NestJS Throttler Redis Storage

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.

0.4.4

2 months ago

0.4.3

2 months ago

0.4.2

2 months ago

0.4.1

8 months ago

0.4.0

8 months ago

0.3.3

12 months ago

0.3.2

12 months ago

0.3.1

12 months ago

0.3.0

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.2.2

1 year ago

0.1.20

2 years ago

0.1.19

2 years ago

0.1.16

2 years ago

0.1.17

2 years ago

0.1.18

2 years ago

0.1.14

3 years ago

0.1.15

3 years ago

0.1.12

3 years ago

0.1.13

3 years ago

0.1.10

3 years ago

0.1.11

3 years ago

0.1.8

3 years ago

0.1.9

3 years ago

0.1.7

3 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago