Skip to content
Latchkey

Redis Cluster "CROSSSLOT Keys don't hash to the same slot" in CI

In Redis Cluster mode a multi-key command must touch keys that all live in the same hash slot. When they do not, Redis returns "CROSSSLOT Keys in request don't hash to the same slot." Tests that pass on standalone Redis can hit this the first time they run against a cluster.

What this error means

A command like MGET, MSET, SUNIONSTORE, or a transaction fails only in cluster mode with "CROSSSLOT Keys in request don't hash to the same slot."

redis-cli
(error) CROSSSLOT Keys in request don't hash to the same slot

Common causes

Multi-key command across different slots

Cluster shards data by slot; a single command that references keys mapping to different slots cannot be served by one node.

No hash tags to co-locate related keys

Without a {tag} in the key names, related keys scatter across slots, so grouped operations fail in cluster mode.

How to fix it

Use hash tags to co-locate keys

  1. Wrap the shared part of related key names in braces so they hash to one slot.
  2. Apply the same tag to every key used together in one command.
  3. Re-run the multi-key operation against the cluster.
Terminal
# both keys hash by the {user:42} tag -> same slot
redis-cli -c mset "{user:42}:name" alice "{user:42}:email" a@x.io

Test against standalone unless cluster is under test

If your app does not require cluster mode, run a single-node Redis in CI so slot rules do not apply.

.github/workflows/ci.yml
services:
  redis:
    image: redis:7
    ports: ['6379:6379']   # standalone, no slots

How to prevent it

  • Use hash tags for keys that participate in multi-key commands.
  • Only run cluster mode in CI when the app actually needs it.
  • Split cross-slot operations into per-slot commands where possible.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →