>_ IzzyLab

Hands-on task

This task is step 12 of the course “Redis in production”

Your own Redis Cluster of three masters

hard~25 min

Build a Redis Cluster of three master nodes on this machine:

  1. Start three redis-server instances on ports 7000, 7001, 7002 in the background with cluster mode enabled. Each node has its own working directory /root/cluster/<port> (its nodes.conf and data will live there).
  2. Join them into a cluster of 3 masters with no replicas — all 16384 slots must be assigned.
  3. Through the cluster, write the key user:42 with the value alice — it must end up on the node that owns its slot and be readable through any node.

The main Redis on 6379 is not needed for this task.

What you'll practise:
  • redis
  • Redis Cluster
  • sharding
  • hash slots
  • redis-cli --cluster
  • MOVED

Topic breakdown

Redis Cluster shards data: the key space is split into 16384 hash slots (CRC16(key) mod 16384), and each slot belongs to one master. Nodes talk over a separate bus (port +10000) and keep their view of the cluster in nodes.conf — every node must have its own file. A client that reaches the wrong node gets a redirect MOVED slot host:port; "smart" clients (and redis-cli -c) follow it and cache the slot map. The cluster is in the ok state only when all slots are covered. Without replicas, losing any master makes its third of the data unavailable — in production each master gets a replica (--cluster-replicas 1).

What's checked

  1. cluster-mode nodes run on 7000–7002
  2. each node has its own /root/cluster/<port> directory with a cluster config
  3. cluster ok: 3 masters, all 16384 slots
  4. user:42 is on the node that owns the slot
  5. another node answers MOVED, and with -c returns user:42

What it looks like