TRYAGAIN: Slot is rehashing, retry the command
A multi-key command hit keys that are being moved between nodes; the cluster asks the client to retry, and the command can succeed then.
- Error prefix
TRYAGAIN- Категория
- Cluster and replication
Что это значит
TRYAGAIN is a temporary refusal, sent only for multi-key commands or Lua scripts whose keys sit in a slot that is being resharded: the command would need keys this node no longer has, and the cluster will not run it half-done. Unlike MOVED or CLUSTERDOWN it does not say the slot map is wrong; it says try the same command again, because once the migration step passes, it will go through.
Clients that follow redirects retry as part of normal handling. By hand, the error shows up while redis-cli --cluster reshard is running against a busy multi-key workload.
Распространённые причины
- A resharding job moved the slot while a multi-key command referenced keys in it.
- A Lua script touched keys in a migrating slot and not all of them are local yet.
- Repeated or interrupted reshard attempts left the slot flagged MIGRATING between runs.
Find the cause
redis-cli -p 7000 CLUSTER NODES | grep -E '\[|myself' redis-cli -p 7000 CLUSTER COUNTKEYSINSLOT 12182 redis-cli -p 7000 CLUSTER SLOTS # Together these show which slot is mid-migration and how many keys remain on the source
Как исправить
-
Retry the same command; the window is usually short:
MGET {u}:a {u}:b # (error) TRYAGAIN Multiple keys request during rehashing of slot # ... a moment later the same command succeeds -
If it persists, check whether the slot is stuck migrating:
redis-cli -p 7000 CLUSTER NODES | grep '\[' # [12182->-...] shows an unfinished migration for slot 12182
-
Finish the job with the cluster tool, or roll the slot back with CLUSTER SETSLOT on both nodes:
Other ways to handle it
Run resharding for multi-key-heavy workloads in low-traffic windows; the TRYAGAIN rate follows your multi-key traffic. Hash tags keep a user's keys together, which shrinks the set of commands that can ever hit a moving slot.
Безопасное воспроизведение
The slot number for the key prefix comes from CLUSTER KEYSLOT '{u}'; the error only fires while keys of that slot are still being moved.
redis-cli --cluster create 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 --cluster-replicas 0
redis-cli -p 7000 MSET {u}:a 1 {u}:b 2
redis-cli -p 7000 CLUSTER SETSLOT <slot-of-{u}> MIGRATING <node-id>
redis-cli -p 7000 MGET {u}:a {u}:b
# (error) TRYAGAIN Multiple keys request during rehashing of slot
redis-cli --cluster reshard 127.0.0.1:7000 # completing the job clears it
Вопросы
Should I back off exponentially on TRYAGAIN?
A short retry is enough. The error only exists while that one slot is moving, and redirect-aware clients already retry it as part of normal handling.
Why not just serve the keys the node still has?
Multi-key commands are atomic by contract. Running them over a subset would silently change what the command means.
Связанные ошибки
ASKThe key is migrating to another nodeCROSSSLOTMulti-key command spans two slotsSQLITE_BUSYSQLite: база данных заблокирована
More cluster and replication errors
READONLYWrite rejected on a read only replicaMASTERDOWNStale data is not allowed to be servedMOVEDThe key lives on another cluster nodeCLUSTERDOWNThe cluster cannot serve this slotNOREPLICASToo few healthy replicas to write
Код и текст сообщения взяты из Redis documentation and source code. Смотрите весь Redis error list или поиск по всем ошибкам баз данных.
Work on Redis in SQLly
A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for Redis and the other databases you use.
Текст и данные на этой странице: CC BY 4.0, с указанием SQLly (sqlly.app). Код и фрагменты SQL: MIT. Подробнее о лицензии Цитируемый текст сообщений об ошибках принадлежит производителю СУБД.