// Redis error reference

CROSSSLOT: Multi-key command spans two slots

The command touched several keys that hash to different slots, which Redis Cluster refuses instead of running a partial command.

Error prefix
CROSSSLOT
카테고리
Cluster and replication
오류 메시지
CROSSSLOT Keys in request don't hash to the same slot

의미

CROSSSLOT is a cluster-only error. A command that names more than one key (MGET, MSET, DEL with several keys, SUNION, Lua scripts) must have all its keys in one hash slot, because a cluster can only run a multi-key command atomically on the node that owns that slot. The keys here hash to different slots, so the node refuses the whole command.

Nothing was executed: DEL, for example, will not delete the keys that do belong to this node. The standard fix is hash tags: name keys so the shared part sits in {braces}, and only the brace content is hashed to a slot.

일반적인 원인

  • A multi-key command named keys that hash to different slots.
  • Keys are tagged per entity ({user:1}:..., {user:2}:...) and a batch command groups several entities at once.
  • A Lua script or a transaction gathers keys from several slots in one call.

Find the cause

redis-cli -p 7000 CLUSTER KEYSLOT key1
redis-cli -p 7000 CLUSTER KEYSLOT key2
# Same number: the command can run. Different numbers: expect CROSSSLOT.

해결 방법

  1. Check the slots the keys map to:

    redis-cli -p 7000 CLUSTER KEYSLOT {user:1000}:profile
    redis-cli -p 7000 CLUSTER KEYSLOT {user:2000}:profile
    # Different slots: the command cannot run as one atomic call
  2. Use hash tags so the keys share a slot:

    MSET {user:1000}:name alice {user:1000}:plan pro
    # Both keys hash on 'user:1000' and land in one slot
  3. When atomicity is not required, split the work into per-key commands:

    DEL {user:1000}:name
    DEL {user:1000}:plan

Other ways to handle it

Pipelines do not have the problem: each command in a pipeline is routed on its own, so a pipeline of SETs works across slots. Reserve same-slot grouping with hash tags for the operations that genuinely need multi-key atomicity.

안전하게 재현하세요

redis-cli -c -p 7000 MSET a 1 b 2
# (error) CROSSSLOT Keys in request don't hash to the same slot
redis-cli -c -p 7000 MSET {d}a 1 {d}b 2
# OK - both keys hash on 'd'

질문

Do pipelines get CROSSSLOT too?

No. Each command in a pipeline is routed separately. The error is only for a single command naming several keys.

Why does the cluster not just forward the command?

Atomicity. A multi-key command has to run as one unit on one node; splitting it across nodes could apply half of it and break the guarantee your data relies on.

관련 오류

More cluster and replication errors

코드와 메시지 텍스트의 출처는 다음과 같습니다 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. 라이선스 세부 정보 인용된 오류 메시지 텍스트의 권리는 해당 데이터베이스 공급업체에 있습니다.