>_ IzzyLab

Hands-on task

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

A Redis replica on a second port

medium~12 min

The main Redis with order data runs on port 6379. Bring up a replica next to it:

  • a second redis-server instance on port 6380, running in the background (as a daemon);
  • data directory — /var/lib/redis-6380;
  • it replicates 127.0.0.1:6379 and receives all of its data;
  • the replica is read-only — writes to it must be rejected.

Don't restart or change the main instance.

What you'll practise:
  • redis
  • replication
  • replicaof
  • INFO replication
  • read-only replica

Topic breakdown

Replication in Redis is asynchronous, "master → replicas". A replica connects to the master (replicaof), receives a full snapshot of the data (full sync via RDB, including diskless — straight into the socket), and then a stream of all write commands. Replicas offload reads from the master and serve as a hot standby: in an outage one of them can be promoted to master (manually or via Sentinel). By default a replica is read-only (replica-read-only yes), otherwise stray writes to it would diverge from the master. Link state is shown by INFO replication: role:slave, master_link_status:up and the master_repl_offset offsets.

What's checked

  1. instance on 6380 runs with directory /var/lib/redis-6380
  2. 6380 is a replica of 127.0.0.1:6379, link up
  3. the replica has all the master's data
  4. a new write to 6379 shows up on 6380
  5. the replica is read-only
  6. master 6379 sees the replica

What it looks like