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

fix - redis keyPrefix option is not supported #1641

Closed
BorisMan9 opened this issue Mar 17, 2024 · 2 comments
Closed

fix - redis keyPrefix option is not supported #1641

BorisMan9 opened this issue Mar 17, 2024 · 2 comments

Comments

@BorisMan9
Copy link

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

@kkoomen
Copy link
Owner

kkoomen commented Mar 20, 2024

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

@kkoomen
Copy link
Owner

kkoomen commented Mar 20, 2024

This has been published to NPM to v0.4.4.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants