Bird
Raised Fist0
Redisquery~10 mins

Replication configuration in Redis - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - Replication configuration
Start Redis Server
↓
Configure Master
↓
Configure Slave
↓
Slave connects to Master
↓
Initial Data Sync
↓
Continuous Replication
↓
Slave updates data
↓
Replication Maintained
This flow shows how Redis replication is set up: start server, configure master and slave, slave connects and syncs data, then keeps replicating changes.
Execution Sample
Redis
CONFIG SET replicaof 127.0.0.1 6379
# Slave connects to master
# Initial sync happens
# Slave replicates ongoing changes
This code configures a Redis instance as a slave to replicate data from the master at 127.0.0.1:6379.
Execution Table
StepActionCommand/ConfigResultNotes
1Start Redis Masterredis-serverMaster running on port 6379Master ready to accept connections
2Start Redis Slaveredis-server --port 6380Slave running on port 6380Slave ready but not replicating yet
3Configure Slave to replicateCONFIG SET replicaof 127.0.0.1 6379Slave connects to masterSlave initiates replication
4Initial SyncSYNC commandSlave receives full datasetSlave data matches master
5Continuous ReplicationPSYNC or SYNCSlave receives updatesSlave stays updated with master
6Write on MasterSET key valueMaster stores dataData change triggers replication
7Replication UpdateReplication streamSlave updates key valueSlave data consistent with master
8Stop replicationCONFIG SET replicaof NO ONESlave stops replicatingSlave becomes standalone
9ExitN/AReplication stopped or server stoppedEnd of replication process
💡 Replication stops when slave is reconfigured or server stops
Variable Tracker
VariableStartAfter Step 3After Step 4After Step 5After Step 7Final
Slave Replication StatusNot replicatingConnecting to masterSynced with masterReceiving updatesData updatedStopped or running
Data on SlaveEmptyEmptyFull copy of masterUpdated with changesMatches masterMatches master or standalone
Key Moments - 3 Insights
Why does the slave need to perform an initial sync after connecting to the master?
Because the slave starts empty or outdated, it must copy the full dataset from the master to have the same data before continuing with live updates. See execution_table step 4.
What happens if the slave loses connection to the master during replication?
The slave will try to reconnect and may perform a partial or full resync depending on the replication offset. This keeps data consistent. See execution_table step 5.
How can you stop a Redis slave from replicating and make it standalone?
By running CONFIG SET replicaof NO ONE on the slave, it stops replication and acts as an independent server. See execution_table step 8.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the slave's replication status after step 4?
ASynced with master
BReceiving updates
CConnecting to master
DNot replicating
💡 Hint
Check the 'Slave Replication Status' in variable_tracker after step 4
At which step does the slave receive the full dataset from the master?
AStep 3
BStep 5
CStep 4
DStep 6
💡 Hint
Look at the 'Initial Sync' row in execution_table
If you run CONFIG SET replicaof NO ONE on the slave, what happens next according to the execution_table?
ASlave starts replicating
BSlave stops replicating
CSlave reconnects to master
DSlave deletes all data
💡 Hint
See step 8 in execution_table for stopping replication
Concept Snapshot
Redis replication setup:
1. Start master and slave servers.
2. Configure slave with CONFIG SET replicaof <master_ip> <port>.
3. Slave connects and performs initial sync.
4. Slave continuously replicates master's changes.
5. Stop replication with CONFIG SET replicaof NO ONE.
Full Transcript
This visual execution shows how Redis replication configuration works step-by-step. First, the master Redis server starts and listens for connections. Then the slave server starts but is not replicating yet. When the slave runs CONFIG SET replicaof with the master's IP and port, it connects to the master and starts replication. The slave performs an initial sync to copy all data from the master. After that, the slave continuously receives updates from the master to keep data consistent. If the slave loses connection, it tries to reconnect and resync. To stop replication, the slave can be reconfigured with CONFIG SET replicaof NO ONE, making it standalone. Variables like replication status and data on the slave change through these steps, as shown in the variable tracker. Key moments include understanding why initial sync is needed, what happens on connection loss, and how to stop replication. The quiz questions test understanding of these steps by referencing the execution table and variable tracker.

Practice

(1/5)
1. What is the primary purpose of Redis replication?
easy
A. To compress data stored on disk
B. To delete old data from the database
C. To copy data from a master server to replicas automatically
D. To encrypt data during transmission

Solution

  1. Step 1: Understand replication concept

    Replication means copying data from one server (master) to others (replicas) automatically.
  2. Step 2: Identify the main goal

    This copying helps keep data safe and allows multiple servers to serve read requests.
  3. Final Answer:

    To copy data from a master server to replicas automatically -> Option C
  4. Quick Check:

    Replication = Data copying [OK]
Hint: Replication means copying data from master to replicas [OK]
Common Mistakes:
  • Confusing replication with data deletion
  • Thinking replication encrypts data
  • Assuming replication compresses data
2. Which Redis command is used to configure a server as a replica of another?
easy
A. REPLICAOF <master_ip> <master_port>
B. CONNECT <master_ip> <master_port>
C. SYNC <master_ip> <master_port>
D. COPYFROM <master_ip> <master_port>

Solution

  1. Step 1: Recall Redis replication commands

    Redis uses the command REPLICAOF (formerly SLAVEOF) to set a server as a replica.
  2. Step 2: Check command correctness

    Only REPLICAOF accepts master IP and port to configure replication.
  3. Final Answer:

    REPLICAOF <master_ip> <master_port> -> Option A
  4. Quick Check:

    Replica config command = REPLICAOF [OK]
Hint: Use REPLICAOF to set replication target server [OK]
Common Mistakes:
  • Using CONNECT which is not a Redis replication command
  • Confusing SYNC with configuration command
  • Inventing COPYFROM which does not exist
3. Given this Redis config snippet:
replicaof 192.168.1.10 6379
replica-read-only yes

What is the effect of replica-read-only yes?
medium
A. The replica rejects write commands and only allows reads
B. The replica can accept write commands from clients
C. The replica disables replication from the master
D. The replica automatically becomes a master

Solution

  1. Step 1: Understand replica-read-only setting

    Setting replica-read-only to yes means the replica will not accept writes from clients.
  2. Step 2: Identify behavior of replica

    The replica only allows read commands and rejects any write commands to keep data consistent with master.
  3. Final Answer:

    The replica rejects write commands and only allows reads -> Option A
  4. Quick Check:

    replica-read-only yes = read-only replica [OK]
Hint: replica-read-only yes means no writes allowed on replica [OK]
Common Mistakes:
  • Thinking replica can write data with this setting
  • Assuming replication stops with this option
  • Believing replica becomes master automatically
4. You run replicaof 192.168.1.20 6379 on a Redis server but replication does not start. What is a likely cause?
medium
A. The command should be replicaof start instead
B. The master IP or port is incorrect or unreachable
C. The replica server has no data to replicate
D. Redis does not support replication

Solution

  1. Step 1: Check network and master details

    If replication does not start, often the master IP or port is wrong or the replica cannot reach the master.
  2. Step 2: Verify command correctness

    The command replicaof with IP and port is correct; no 'start' keyword is needed.
  3. Final Answer:

    The master IP or port is incorrect or unreachable -> Option B
  4. Quick Check:

    Replication fails if master unreachable [OK]
Hint: Check master IP and port if replication fails [OK]
Common Mistakes:
  • Using wrong command syntax like replicaof start
  • Assuming replication needs data on replica first
  • Thinking Redis does not support replication
5. You want to set up a Redis replica that can serve read requests but also allow some writes during maintenance. Which configuration is best?
hard
A. Use replicaof <master_ip> <master_port> and set replica-read-only yes
B. Set the replica as master with no replication
C. Do not use replication; instead manually copy data
D. Use replicaof <master_ip> <master_port> and set replica-read-only no

Solution

  1. Step 1: Understand replica-read-only option

    Setting replica-read-only to no allows writes on the replica, useful during maintenance.
  2. Step 2: Combine with replication setup

    Using replicaof configures replication; setting replica-read-only no allows writes while still replicating.
  3. Final Answer:

    Use replicaof <master_ip> <master_port> and set replica-read-only no -> Option D
  4. Quick Check:

    replica-read-only no allows writes on replica [OK]
Hint: Set replica-read-only no to allow writes on replica [OK]
Common Mistakes:
  • Assuming replica-read-only yes allows writes
  • Thinking manual copy replaces replication
  • Confusing replica with master roles
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard