TRYAGAIN error
A command accessed multiple keys while their hash slot was being migrated between cluster nodes.
A Redis cluster returns this error when a command with several keys runs while their hash slot is moving to another node. Some of the keys are still on the old node, and some aren't, so neither node can run the command. The error is temporary. It stops when the slot has finished moving.
TRYAGAIN Multiple keys request during rehashing of slot
A similar error, TRYAGAIN Slot is being trimmed, means that a write reached a node while it was deleting all the keys of the slot, for example, after SFLUSH. It's temporary too.
In client libraries
| Client library | Exception or error type | Message |
|---|---|---|
| redis-py | TryAgainError |
Multiple keys request during rehashing of slot |
| Jedis | JedisDataException |
TRYAGAIN Multiple keys request during rehashing of slot |
| node-redis | SimpleErrorTest with err.message.startsWith('TRYAGAIN') |
TRYAGAIN Multiple keys request during rehashing of slot |
| Lettuce The async API wraps the exception in an ExecutionException (get()) or a CompletionException (join()). |
RedisCommandExecutionException |
TRYAGAIN Multiple keys request during rehashing of slot |
| go-redis | redis.ErrorTest with redis.IsTryAgainError(err) |
TRYAGAIN Multiple keys request during rehashing of slot |
| ioredis | ReplyErrorTest with err.message.startsWith('TRYAGAIN') |
TRYAGAIN Multiple keys request during rehashing of slot |
| StackExchange.Redis NRedisStack uses StackExchange.Redis, so it raises the same exceptions. The sync and async APIs raise the same exceptions. |
RedisServerException |
TRYAGAIN Multiple keys request during rehashing of slot |
| Predis | Predis\Response\ServerExceptionTest with $e->getErrorType() === 'TRYAGAIN' |
TRYAGAIN Multiple keys request during rehashing of slot |
| redis-rb | Redis::CommandError |
TRYAGAIN Multiple keys request during rehashing of slot (redis://<host>:<port>) |
| redis-rs The sync and async APIs raise the same errors. |
ErrorKind::Server(ServerErrorKind::TryAgain) |
TryAgain: Multiple keys request during rehashing of slot |
Example
During the move, the old node still has user:{42}:profile, but user:{42}:cart is already on the new node:
> MGET user:{42}:profile user:{42}:cart
(error) TRYAGAIN Multiple keys request during rehashing of slot
How to fix it
Wait a moment and send the command again. Cluster clients usually retry for you. For example, redis-py's RedisCluster retries the command a few times. If the slot is still moving after that, it raises ClusterError: TTL exhausted.
If the error doesn't go away, the slot may be stuck in the middle of a move. To check, run redis-cli --cluster check <host>:<port>. It lists any slots that are still open, which means they're being moved. See Scale with Redis Cluster.