node.jsamazon-web-servicesredisamazon-memory-db

AWS Redis Cluster MOVED Error using redis node library


I have created a Redis MemoryDB cluster with 2 nodes in AWS: enter image description here

I connect to it using redis node library v4.0.0 like this:

import { createCluster } from 'redis';
(async () => {
    const REDIS_USERNAME = 'test-username';
    const REDIS_PASSWORD = 'test-pass';
    const cluster = createCluster({
        rootNodes: [
            {
                url: `rediss://node1.amazonaws.com:6379`,
            },
            {
                url: `rediss://node2.amazonaws.com:6379`,
            },
        ],
        defaults: {
            url: `rediss://cluster.amazonaws.com:6379`,
            username: REDIS_USERNAME,
            password: REDIS_PASSWORD,
        }
    });
    cluster.on('error', (err) => console.log('Redis Cluster Error', err));
    await cluster.connect();
    console.log('connected to cluster...');
    await cluster.set('key', 'value');
    const value = await cluster.get('key');
    console.log('Value', value);
    await cluster.disconnect();
})();

But sometimes I get the error ReplyError: MOVED 12539 rediss://node2.amazonaws.com:6379 and I cannot get the value from the key.

Do you have any idea if there is something wrong with the configuration of the cluster or with the code using redis node library?

Edit: I tried it with ioredis library and it works, so it's something wrong with the redis library.

Node.js Version: 16

Redis Server Version: 6


Solution

  • I had created an issue to redis library, so it's going to be solved soon with this PR.