In Redis Cluster mode, a multi-key command is being executed while slot migration/rehashing is in progress. The command cannot be executed because the keys are split between the source and destination nodes. This error instructs the client to retry the operation after the resharding completes.
The TRYAGAIN error in Redis Cluster occurs during slot migration when a multi-key command (like MGET, MSET, DEL with multiple keys) is unable to execute because the keys involved are distributed across multiple nodes due to an ongoing reshard operation. Redis cannot serve this command in one operation since some keys may be on the current node while others are being migrated to a different node. This is a temporary condition that resolves once the slot migration completes. The error signals that the client should retry the command after waiting for the resharding to finish.
The TRYAGAIN error only appears in Redis Cluster mode during active slot migration. It indicates a temporary condition where your command cannot be executed because the involved keys are split between nodes during resharding.
Verify you are using Redis Cluster:
redis-cli CLUSTER INFOIf the output shows cluster_state:ok, your cluster is healthy. If it shows cluster_state:fail or ongoing migration, a reshard is in progress.
Add exponential backoff retry logic when you encounter TRYAGAIN errors. Most Redis clients provide built-in retry mechanisms.
Node.js (node-redis):
const { createClient } = require('redis');
const client = createClient({
socket: {
host: 'localhost',
port: 6379,
},
// Enable automatic retry
retryStrategy: (retries) => {
if (retries > 10) return new Error('Max retries exceeded');
return Math.min(retries * 50, 500); // Exponential backoff
},
});
await client.connect();Python (redis-py):
import redis
from redis.retry import Retry
from redis.backoff import ExponentialBackoff
retry = Retry(ExponentialBackoff(), 10)
client = redis.Redis(
host='localhost',
port=6379,
retry=retry,
retry_on_timeout=True
)The best way to avoid TRYAGAIN errors is to ensure all keys in a multi-key operation hash to the same slot using Redis hash tags.
Hash tags force keys to the same slot by extracting only the text between curly braces for hash computation:
# Without hash tags - keys may be on different slots
redis.mset({'user:1:name': 'Alice', 'user:2:name': 'Bob'})
# With hash tags - keys map to the same slot
redis.mset({'{user:1}:name': 'Alice', '{user:1}:profile': '{...}'})
redis.mset({'{user:2}:name': 'Bob', '{user:2}:settings': '{...}'})The {user:1} portion (inside braces) is hashed, so all keys with the same tag are guaranteed on the same slot.
If you control the cluster, you can monitor resharding progress:
# Check cluster status
redis-cli CLUSTER NODES
# Monitor migrations in progress
redis-cli CLUSTER SLOTSOnce all slots show OK state and migrations complete, TRYAGAIN errors will cease. If you initiated a reshard manually via redis-cli CLUSTER MEET or a cluster manager, wait for the operation to finish before running multi-key commands on keys spanning different slots.
If you frequently encounter TRYAGAIN errors during normal cluster operations, consider your resharding approach:
Option 1: Disable auto-resharding during peak hours
Postpone manual cluster rebalancing to maintenance windows when traffic is low.
Option 2: Use gradual migration
Some cluster managers allow slow/graceful migrations that minimize disruptions.
Option 3: Increase timeout values
Allow clients more time for retry-able operations:
import redis
client = redis.Redis(
host='localhost',
port=6379,
socket_timeout=10, # Longer timeout for client operations
socket_keepalive=True,
)Redis 7.0+ optimized TRYAGAIN behavior: before Redis 7.0, if some keys existed during migration, the cluster might return ASK redirects. Starting with Redis 7.0, if any keys are missing during a multi-key command on a migrating node, TRYAGAIN is returned immediately (instead of ASK), allowing the client to retry faster. This reduces unnecessary network hops. For cloud-hosted Redis Cluster (Redis Cloud, AWS MemoryDB, Azure Cache), resharding is often automatic and transparent, but clients may still encounter temporary TRYAGAIN errors. Use the cloud provider's SDK or client library, which typically includes built-in retry logic. If you are running your own Redis Cluster, consider using a cluster manager like Redis Cluster Proxy or Codis, which can handle resharding more gracefully. Avoid executing non-idempotent operations (like INCR or LPUSH) in retry loops, as they may execute multiple times.
ERR Unbalanced XREAD list of streams
How to fix "ERR Unbalanced XREAD list" in Redis
ERR syntax error
How to fix "ERR syntax error" in Redis
ConnectionError: Error while reading from socket
ConnectionError: Error while reading from socket in redis-py
ERR unknown command
How to fix ERR unknown command in Redis
Command timed out
How to fix 'Command timed out' in ioredis