Redis Cluster chia key space thành 16384 hash slots (0-16383).
- Mỗi key được assign slot =
CRC16(key) % 16384. - Cluster có N master nodes, mỗi master sở hữu một range slot (ví dụ: 3 masters mỗi master có ~5461 slots). MOVED redirect: khi client gửi request đến node sai (key không thuộc slot của node đó), node trả về
MOVED <slot> <ip:port>— client phải resend đến đúng node. - Smart client cache slot map để tránh redirect (redis-py, Jedis, ioredis tự handle). ASK redirect: trong quá trình resharding (migrate slot giữa nodes), một số key đã migrate, số khác chưa.
- Node cũ trả
ASK <slot> <new_node>cho key đã migrate — client gửiASKING+ request đến node mới một lần (không cache như MOVED). Key tags:{user_id}.orders— chỉ hashuser_idphần trong{}, đảm bảo keys liên quan cùng slot để dùng multi-key commands. - Cluster yêu cầu ít nhất 6 nodes (3 master + 3 replica) để đảm bảo HA.
Redis Cluster divides the key space into 16384 hash slots (0–16383).
- Each key is assigned a slot =
CRC16(key) % 16384. - The cluster has N master nodes, each owning a range of slots (e.g., 3 masters each own ~5461 slots). MOVED redirect: when a client sends a request to the wrong node (the key's slot is not owned by that node), the node returns
MOVED <slot> <ip:port>— the client must resend to the correct node. - Smart clients cache the slot map to avoid redirects (redis-py, Jedis, ioredis handle this automatically). ASK redirect: during resharding (migrating a slot between nodes), some keys have already moved and some haven't.
- The source node returns
ASK <slot> <new_node>for a migrated key — the client sendsASKING+ the request to the new node once (not cached like MOVED). Key tags:{user_id}.orders— onlyuser_id(the part inside{}) is hashed, ensuring related keys land on the same slot so multi-key commands can be used. - Cluster requires at least 6 nodes (3 masters + 3 replicas) to guarantee HA.