0

I am trying to connect to AWS Elastic Cache Redis Cluster and i keep getting this I am still getting the Error MOVED 12218 ip:6379

Following is the code

https://www.npmjs.com/package/redis - redis: ^4.0.1

import {createClient} from "redis";
const client = createClient({url: "redis://xyz.abc.clustercfg.use2.cache.amazonaws.com:6379"});
await client.connect();
console.log("client connected");
console.log(await client.ping());

OUTPUT:

client connected
PONG

But when I do await client.get(key) or await client.set(key, value) I get the MOVED error.

I even followed this https://github.com/redis/node-redis/issues/1782, but yet i am getting the same MOVED 12218 ip:6379 error.

Rajan Shah
  • 95
  • 1
  • 2
  • 10
  • Not a JS expert but you need to connect to Redis clusters in a different way. Same underlying logic as my answer here - https://stackoverflow.com/a/71101587/4800344 - however the code will be different. – Ermiya Eskandary Jun 09 '22 at 21:40

2 Answers2

1

I am hoping you are trying cluster mode enabled redis in aws.

"redis": "^4.1.0".

I am using this redis version If so then you can try this below code

    const redis = require('redis');

    const client = redis.createCluster({
      rootNodes: [
        {
          url: `redis://${ConfigurationEndpoint}:${port}`,
        },
      ],
      useReplicas: true,
     });
dead_webdev
  • 164
  • 2
  • 9
0

Just some info. I realized that I set up a Redis-Cluster Helm chart but I was connecting with Jedis from a Sentinel/Redis setup. Once I changed Jedis to connect with JedisCluster then this error went away. Now this is with a client so your setup might be different, but something to look at.

user3008410
  • 644
  • 7
  • 15