Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants