kkoomen/nestjs-throttler-storage-redis

fix - redis keyPrefix option is not supported

Closed this issue · 2 comments

configuring a keyPrefix in RedisOptions doesnt seem to be supported

configure whatever you want as the keyPrefix:

ThrottlerModule.forRootAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: (config: ConfigService) => ({
        throttlers: [
          {
            ttl: config.get('THROTTLE_TTL'),
            limit: config.get('THROTTLE_LIMIT'),
          },
        ],
        storage: new ThrottlerStorageRedisService(
        {
        host: config.get('REDIS_HOST'),
        port: config.get('REDIS_PORT'),
        keyPrefix: 'my-very-special-prefix',
      }),
      }),
    }),

the redis key will still remain the same

Hi,

Good catch! This was added, but got lost due to a refactoring from last version. I've added it. You can now add prefixes again like so:

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.

      // redis object
      storage: new ThrottlerStorageRedisService(new Redis({ keyPrefix: 'local-' )),

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

This has been published to NPM to v0.4.4.