Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Databases and Redis

Redis answers MOVED with a slot number and another node's address

Your error

MOVED 3999 127.0.0.1:63811 more line it can show

Fix it fast

Most common cause, 1 of 3

The application uses a single-node client against a cluster

Create the connection with your library's cluster client.

Fix
// node-redis 6
import { createCluster } from 'redis';
const cluster = await createCluster({
  rootNodes: [{ url: 'redis://10.0.0.1:6379' }],
  defaults: { password: process.env.REDIS_PASSWORD }
}).on('error', err => console.error('Redis Cluster Error', err)).connect();

// ioredis 6
const cluster = new Redis.Cluster([{ host: '10.0.0.1', port: 6379 }]);

# redis-py 8
from redis.cluster import RedisCluster
rc = RedisCluster(host='10.0.0.1', port=6379)
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

A Redis MOVED reply means the node you asked does not own that key's hash slot, and it names the node that does. Cluster-aware clients follow it silently, so seeing it means your client or redis-cli runs in single-node mode. Use createCluster, Redis.Cluster or RedisCluster, run redis-cli -c, or use a proxied endpoint. Applies to Redis 8.10.

  • Applies to Redis Open Source 8.10.3, node-redis 6.3.1, ioredis 6.0.0, redis-py 8.1.0, Azure Managed Redis
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Ask the endpoint whether it runs as a cluster, and which slot your key maps to. cluster_enabled:1 together with a MOVED reply means the client has to speak the cluster protocol or go through a proxy.

Run this first
redis-cli -h my-redis.example.com -p 6379 INFO cluster
redis-cli -h my-redis.example.com -p 6379 CLUSTER KEYSLOT user:42

Then find the line you see in this list and open its fix:

  1. 1The application uses a single-node client against a clusterSome keys work and others fail with MOVED, and the code builds its connection with createClient, new Redis() or redis.Redis
  2. 2redis-cli was started without cluster modeThe error appears in an interactive redis-cli session as (error) MOVED, while the application itself works
  3. 3Azure Managed Redis uses the OSS cluster policy with a client that cannot follow itThe host ends in redis.azure.net, you connect on port 10000, and the MOVED replies point to ports in the 85xx range

What does the error look like?

  • MOVED 3999 127.0.0.1:6381
  • (error) MOVED 12182 127.0.0.1:7002

Cause 1 of 3

The application uses a single-node client against a cluster

You seeSome keys work and others fail with MOVED, and the code builds its connection with createClient, new Redis() or redis.Redis

Check

Redis Cluster nodes never proxy commands. A node that does not serve a key's hash slot replies with MOVED, the slot and the right node's address, and expects the client to resend the command there. A plain client treats that reply as an error, so only keys that happen to live on the node you connected to succeed.

Check
grep -rnE "createClient\(|new Redis\(|redis\.Redis\(" src

Fix

Create the connection with your library's cluster client. It learns which node owns each slot, sends every command there and follows MOVED replies for you. In node-redis, put shared options such as password and TLS under defaults, because settings on rootNodes only apply to the discovery connection.

Fix
// node-redis 6
import { createCluster } from 'redis';
const cluster = await createCluster({
  rootNodes: [{ url: 'redis://10.0.0.1:6379' }],
  defaults: { password: process.env.REDIS_PASSWORD }
}).on('error', err => console.error('Redis Cluster Error', err)).connect();

// ioredis 6
const cluster = new Redis.Cluster([{ host: '10.0.0.1', port: 6379 }]);

# redis-py 8
from redis.cluster import RedisCluster
rc = RedisCluster(host='10.0.0.1', port=6379)

Verify

Reads and writes for keys in different slots all succeed, and no MOVED reaches your logs.

Verify
redis-cli -c -h 10.0.0.1 -p 6379 GET user:42

Confirmed by redis.io

Did this fix it?

Cause 2 of 3

redis-cli was started without cluster mode

You seeThe error appears in an interactive redis-cli session as (error) MOVED, while the application itself works

Check

redis-cli stays on the node you connected to unless you start it with -c. With that flag it follows -ASK and -MOVED redirections and prints Redirected to slot instead of an error.

Check
redis-cli -h 10.0.0.1 -p 6379 GET user:42

Fix

Reconnect with -c, which makes redis-cli follow each redirection to the node that owns the slot.

Fix
redis-cli -c -h 10.0.0.1 -p 6379

Verify

Commands on any key return a value, with a Redirected to slot line when the key lives elsewhere.

Verify
redis-cli -c -h 10.0.0.1 -p 6379 SET user:42 ok

Confirmed by redis.io

Did this fix it?

Cause 3 of 3

Azure Managed Redis uses the OSS cluster policy with a client that cannot follow it

You seeThe host ends in redis.azure.net, you connect on port 10000, and the MOVED replies point to ports in the 85xx range

Check

Under the OSS clustering policy, Azure Managed Redis exposes the Redis Cluster API: the first connection goes to port 10000 and the client must then open its own connections to shards on 85xx ports. TLS is required by default on all of them. Older or specialised client libraries that cannot do this see the redirections as errors.

Check
REDISCLI_AUTH="$REDIS_KEY" redis-cli -h my-cache.region.redis.azure.net -p 10000 --tls --cacertdir /etc/ssl/certs INFO cluster

Fix

Switch the application to a cluster-capable client as in cause 1, with TLS also set for the shard connections. If that library cannot speak the cluster API, use the Enterprise clustering policy instead, which routes every request through a single proxy endpoint.

Fix
// node-redis 6: TLS must be set for the discovered shard connections too
const cluster = await createCluster({
  rootNodes: [{ url: 'rediss://my-cache.region.redis.azure.net:10000' }],
  defaults: { password: process.env.REDIS_KEY, socket: { tls: true } }
}).connect();

Verify

The application reads keys from every shard without MOVED errors.

Verify
REDISCLI_AUTH="$REDIS_KEY" redis-cli -c -h my-cache.region.redis.azure.net -p 10000 --tls --cacertdir /etc/ssl/certs GET user:42

Confirmed by learn.microsoft.com

Did this fix it?

How do I stop it coming back?

  • Wrap Redis connection setup in one module that chooses the cluster client from configuration, so no other file calls createClient against a cluster endpoint.
  • Never hardcode the shard addresses or 85xx ports from a MOVED reply; they can change, and a cluster client discovers them for you.
  • Run integration tests against a small cluster rather than a single node when production uses clustering, so single-node code paths fail in CI.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: TaxiDex, Raheeb.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.