How to fix TRYAGAIN Multiple keys request during rehashing in Redis
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.
Quick fix
Fixes TRYAGAIN Multiple keys request during rehashing
redis-cli CLUSTER INFO- Understand the error and when it occurs
- Implement retry logic in your client
- Use hash tags to keep related keys on the same slot
- Wait for cluster resharding to complete
redis-cli CLUSTER INFOTRYAGAIN Multiple keys request during rehashing
What this error means
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.
Typical symptoms
- Multi-key Redis commands fail with TRYAGAIN error during cluster scaling or rebalancing
- Commands like MGET, MSET, DEL across multiple keys fail intermittently during cluster operations
- Error appears specifically when executing commands on keys that span different hash slots
- Application experiences temporary failures during Redis Cluster resharding
- Errors are temporary and resolve after the resharding operation completes
Common causes
- Redis Cluster is actively migrating slots (resharding) and a multi-key command touches keys in both source and destination nodes
- Client is executing commands on keys that are split between nodes during migration
- Multi-key operations involving keys with different hash slots that are being rebalanced
- Cluster topology change triggered a resharding operation that conflicts with your command
How to fix "TRYAGAIN Multiple keys request during rehashing"
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,
)Advanced notes
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.
Frequently asked questions
- What does "TRYAGAIN Multiple keys request during rehashing" mean?
- 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.
- How do I fix "TRYAGAIN Multiple keys request during rehashing"?
- 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.
- What causes "TRYAGAIN Multiple keys request during rehashing"?
- Redis Cluster is actively migrating slots (resharding) and a multi-key command touches keys in both source and destination nodes Client is executing commands on keys that are split between nodes during migration Multi-key operations involving keys with different hash slots that are being rebalanced
- Is the "TRYAGAIN Multiple keys request during rehashing" error serious?
- It is a medium-severity error โ more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- ๐Redis Official Documentation
- ๐Redis Cluster Specification - Cluster Slots(Official Docs)
- ๐Redis Client Error Handling Guide(Official Docs)