AWS Redis Cluster MOVED Error using redis node library
Asked Answered
O

1

6

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

Obstructionist answered 21/1, 2022 at 10:13 Comment(2)
Are you sure the URLs you're using is redis & not rediss ?Got
I use rediss. The second s stands for connection using tls.Obstructionist
O
1

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

Obstructionist answered 18/2, 2022 at 8:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.