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

Migrate to v4 guidance is not good enough #1211

Closed
zhuxb711 opened this issue Nov 15, 2024 · 4 comments
Closed

Migrate to v4 guidance is not good enough #1211

zhuxb711 opened this issue Nov 15, 2024 · 4 comments
Labels

Comments

@zhuxb711
Copy link

Describe the bug
I'm using latest v3 keyv/redis currently. There is no enough information about how to migrate from v3 to v4 if using cluster replica set within k8s. In v4, using createCluster and it requests 'rootNodes' but in k8s we don't need to provide the node IP address, just provide a host URL. Would you please let me know how to migrate to v4?

Here is the code about how I make it work in v3:

new KeyvRedis(new Redis.Cluster(
            [
              {
                host: configService.getOrThrow<string>('REDISDB_HOST'),
                port: Number(configService.getOrThrow<string>('REDISDB_PORT'))
              }
            ],
            {
              scaleReads: configService.getOrThrow<NodeRole>('REDISDB_READ_PREFERENCE'),
              enableReadyCheck: true,
              enableOfflineQueue: true,
              redisOptions: {
                autoResubscribe: true,
                autoResendUnfulfilledCommands: true,
                socketTimeout: ms(configService.getOrThrow<string>('REDISDB_SOCKET_TIMEOUT')),
                connectTimeout: ms(configService.getOrThrow<string>('REDISDB_CONNECT_TIMEOUT')),
                maxRetriesPerRequest: Number(configService.getOrThrow<string>('REDISDB_MAX_RETRY_ATTEMPTS_PER_REQUEST'))
              },
              clusterRetryStrategy: (times, reason) => {
                if (times <= Number(configService.getOrThrow<string>('REDISDB_MAX_CLUSTER_RETRY_ATTEMPTS'))) {
                  const nextDelay = Math.min(
                    100 * Math.pow(2, times),
                    ms(configService.get<string>('REDISDB_RETRIES_MAX_BACKOFF_LIMIT'))
                  );
                  return nextDelay;
                }

                throw new Error(`Unable to connect to the redis cluster and throttler guard could not be setup`);
              }
            }
          ))
@zhuxb711 zhuxb711 added the bug label Nov 15, 2024
@jaredwray
Copy link
Owner

@zhuxb711 - thanks for sending in the issue. The new redis driver is based on node-redis which you can follow their documentation on createCluster.

You can read more on this here and post any issues that you encounter in that repo. https://github.com/redis/node-redis/blob/master/docs/clustering.md

I will add in the link to this documentation in ours to help.

@jaredwray
Copy link
Owner

#1212

@zhuxb711
Copy link
Author

I got type not assignable error from v4.0.1

        const cluster = createCluster({
          rootNodes: [
            {
              url: `redis://host:port`
            }
          ],
          useReplicas: true
        });
        
        const key = new Keyv({
          store: new KeyvRedis(cluster) // cluster is not assignable to the constructor of 'KeyvRedis'
        });

@jaredwray
Copy link
Owner

@zhuxb711 the type issue should be resolved in v4.0.2 please note that when using clustering clear() and iterator() do not work due to the lack of SCAN in clustering.

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

No branches or pull requests

2 participants