{
  "schema_version": 2,
  "id": "develop/reference/errors/common/crossslot",
  "title": "CROSSSLOT error",
  "url": "https://redis.io/docs/latest/develop/reference/errors/common/crossslot/",
  "summary": "A command used keys that belong to different hash slots.",
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-11-02T15:10:28+01:00",
  "page_type": "content",
  "content_hash": "24b7c7cf69a551634027ce8d1778bc86ee47714316a9c0b328973ad29b74a0f2",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "A Redis cluster returns this error when one command uses keys that belong to different hash slots. A cluster splits keys into 16384 hash slots, and different nodes can serve different slots. A command that uses several keys, such as [`MSET`](https://redis.io/docs/latest/commands/mset) or [`MGET`](https://redis.io/docs/latest/commands/mget), only works when all of its keys are in the same slot.\n\n[code example]\n\nIn redis-py, this error is `ClusterCrossSlotError: Keys in request don't hash to the same slot`."
    },
    {
      "id": "example",
      "title": "Example",
      "role": "example",
      "text": "The keys `user:1` and `user:2` are in different slots, so you can't read them with one `MGET`:\n\n[code example]"
    },
    {
      "id": "how-to-fix-it",
      "title": "How to fix it",
      "role": "content",
      "text": "- **Use hash tags to put related keys in the same slot.** When a key name has a part in curly braces, Redis uses only that part to choose the slot. So `user:{42}:profile` and `user:{42}:cart` are always in the same slot:\n\n    [code example]\n\n    Put the braces around the part that the keys share, such as a user ID. Don't give too many keys the same tag. All keys with the same tag are stored on the same node. See [Hash tags](https://redis.io/docs/latest/operate/oss_and_stack/reference/cluster-spec#hash-tags).\n- **Split the command.** Send one command for each key, or one for each group of keys in the same slot. Some cluster clients can do this for you. For example, redis-py's `RedisCluster` has `mget_nonatomic()` and `mset_nonatomic()`. As the names say, the keys are then no longer read or written in one step.\n\nTransactions and Lua scripts follow the same rule: all the keys they use must be in the same slot. See [Multi-key operations](https://redis.io/docs/latest/develop/using-commands/multi-key-operations)."
    }
  ],
  "examples": [
    {
      "id": "overview-ex0",
      "language": "plaintext",
      "code": "CROSSSLOT Keys in request don't hash to the same slot",
      "section_id": "overview"
    },
    {
      "id": "example-ex0",
      "language": "plaintext",
      "code": "> CLUSTER KEYSLOT user:1\n(integer) 10778\n> CLUSTER KEYSLOT user:2\n(integer) 6777\n> MGET user:1 user:2\n(error) CROSSSLOT Keys in request don't hash to the same slot",
      "section_id": "example"
    },
    {
      "id": "how-to-fix-it-ex0",
      "language": "plaintext",
      "code": "> CLUSTER KEYSLOT user:{42}:profile\n    (integer) 8000\n    > CLUSTER KEYSLOT user:{42}:cart\n    (integer) 8000\n    > MSET user:{42}:profile \"...\" user:{42}:cart \"...\"\n    OK",
      "section_id": "how-to-fix-it"
    }
  ]
}
