redis / ioredis

🚀 A robust, performance-focused, and full-featured Redis client for Node.js.
MIT License
14.39k stars 1.2k forks source link

Redis Cluster keyPrefix doesn't work in redisOptions #1024

Closed wangyx233 closed 4 years ago

wangyx233 commented 4 years ago

version: 4.14.1 According to doc, I think keyPrefix in redisOptions. But it doesn't work. Like blow:

const redisClient = new Redis.Cluster(nodes, {
  redisOptions: {
    keyPrefix: 'foo:',
  }
});

After attempts, it actually works in root option, like this:

const redisClient = new Redis.Cluster(nodes, {
    keyPrefix: 'foo:',
});

Is it by design?

zhongshan1993 commented 4 years ago

I reproduced this bug too.

cobolbaby commented 4 years ago

+1

henrikhaugboelle commented 4 years ago

+1

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 7 days if no further activity occurs, but feel free to re-open a closed issue if needed.

aaronleesmith commented 4 years ago

This issue was left to die on the vine with an open PR, but it is critical to the functionality of key prefixing. The workaround is to include keyPrefix one level up (on the object which is the second parameter to new Cluster) but the type definitions will yell at you for trying to do that. So you end up having to do something like this:

new Cluster(nodes, clusterRetryStrategy: { this.clusterRetryStrategy,
      redisOptions: {
        maxRetriesPerRequest: 1,
        keyPrefix: `${this.config.RedisNamespace}:`,
      },
      /**
       * The entry below fixes a bug where the keyPrefix is totally ignored when used in cluster mode.
       * The issue has an open PR: https://github.com/luin/ioredis/issues/1024
       */
      keyPrefix: `${this.config.RedisNamespace}:`
} as any)

It would be great if this PR were merged and this was resolved.

joseph-jja commented 3 years ago

Just installed ioredis this week, so using latest. I am still seeing this issue. Thankfully I found this issue and was able to use this workaround.

anton-johansson commented 2 years ago

I also just noticed this issue. While the workaround does work, it's a bit tedious when using TypeScript, since keyPrefix is technically not valid on that location.

Any chance this issue can be re-opened? To avoid the workaround and also to avoid future confusion for other people. :)

glensc commented 2 years ago

would be nice if the fix be ported to 4.x

florian-besser commented 1 year ago

Just encountered this issue using the old 4.x.x version of IoRedis. It would be great to either backport this feature or remove keyPrefix from the TypeScript types for 4.x.x so people are not led to believe this feature is supported, when it isn't.