sprash
sprash

Reputation: 345

Why does Redis give "moved" error every 2 minutes

Redis is giving MOVED error. I am using enterprise tier for the Azure Cache for Redis. Using the below Node.js code to interact with it.

const redis = require('redis');

const client = redis.createClient({
    url: "dns",
    password: "***",
    connectTimeout: 100000
});

Upvotes: 1

Views: 1515

Answers (1)

Guy Royse
Guy Royse

Reputation: 4312

A MOVED messages means that the key you are looking for is not on the particular shard in the cluster. It has been moved to another shard or was never on this shard. Typically this is handled by Node Redis for you and you just get your values back.

However, Node Redis needs to be told that it is connecting to a cluster to do this. You do this by calling .createCluster instead of .createConnection. There is a guide with all the details for this, but the short version is:

import { createCluster } from 'redis';

const cluster = createCluster({
  rootNodes: [
    {
      url: 'redis://10.0.0.1:30001'
    },
    {
      url: 'redis://10.0.0.2:30002'
    }
  ]
})

Upvotes: 1

Related Questions