Typorithm · medium

Replication

redis-replicationredisreplicareplicaofha
Saved on this device
Full lesson · 8 learning steps Open any exercise for focused practice
1

Step 1 of 8 · intro card

Learn Replication

0%

Persistence & Scale

REPLICAOF turns a node into an async replica of a master (read scaling and failover); INFO replication shows role and lag; REPLICAOF NO ONE promotes a replica to master; WAIT blocks until N replicas ack writes for tunable durability. Replication is asynchronous by default, so a failover can lose un-acked writes.

REPLICAOF master 6379 makes the current node an asynchronous replica of the named master. Replicas copy the master's data and stay read-only, which scales reads and provides a standby for failover. INFO replication reports each node's role and how far a replica lags behind its master.

REPLICAOF NO ONE breaks the link and promotes a replica to a standalone master — the core of a manual failover. Because replication is asynchronous, writes acknowledged by the old master may not have reached the replica yet, so a failover can lose them.

WAIT 1 100 gives you tunable durability: it blocks until at least one replica acknowledges the preceding writes, or until the 100 ms timeout elapses. CONFIG GET reads runtime settings such as maxmemory, which you typically keep consistent across master and replicas.

01

REPLICAOF makes a node an async replica of a master.

02

REPLICAOF NO ONE promotes a replica to master.

03

WAIT blocks until N replicas ack the writes.

REPLICAOF master 6379
INFO replication
REPLICAOF NO ONE
WAIT 1 100
CONFIG GET maxmemory

Read the implementation

Connect each part of the code to the concept before you type.

1. Become a replica

REPLICAOF makes this node an asynchronous replica of the given master host and port.

REPLICAOF master 6379

2. Inspect role

INFO replication shows whether this node is a master or replica and how far behind it is.

INFO replication

3. Promote to master

REPLICAOF NO ONE detaches the replica and promotes it to an independent master.

REPLICAOF NO ONE

4. Wait for acks

WAIT blocks until at least 1 replica acknowledges the prior writes, or the 100 ms timeout passes.

WAIT 1 100

5. Read config

CONFIG GET reads a runtime setting, here the memory limit, which should match across nodes.

CONFIG GET maxmemory

A complete learning loop

01

Understand

Read the concept map and follow the code breakdown.

02

Reconstruct

Type the implementation, repair mistakes and work through every recall exercise.

03

Verify

Use the final check without hints; revisit weak concepts in short practice sessions.

Replication: Lesson & Practice · Typorithm | ApplyDjinn