📖 Scenario: You are setting up a simple Redis database system for a small online store. To ensure data safety and availability, you want to create a master-replica setup where the master handles writes and the replica keeps a copy for reads and backup.
🎯 Goal: Build a Redis master-replica architecture configuration with one master and one replica. You will create the master data, configure the replica to follow the master, and verify the replication setup.
📋 What You'll Learn
Create a Redis master instance with initial data
Configure a Redis replica instance to replicate the master
Verify the replication status on the replica
Use exact Redis commands and configuration keys as specified
💡 Why This Matters
🌍 Real World
Master-replica architecture is used in real-world applications to improve data availability and reliability by keeping copies of data on multiple servers.
💼 Career
Understanding master-replica setup is important for roles like database administrators, backend developers, and system engineers who manage scalable and fault-tolerant data systems.
Progress0 / 4 steps
1
Create the Redis master data
Use the Redis command SET to create a key called product:1001 with the value Laptop on the master instance.
Redis
Hint
Use the SET command followed by the key and the value.
2
Configure the replica to follow the master
Use the Redis command REPLICAOF with the master IP 127.0.0.1 and port 6379 to configure the replica instance to follow the master.
Redis
Hint
Use REPLICAOF followed by the master's IP and port to set up replication.
3
Check the replication status on the replica
Use the Redis command INFO replication on the replica instance to check the replication status and confirm it is connected to the master.
Redis
Hint
Run INFO replication to see if the replica is connected to the master.
4
Verify data replication on the replica
Use the Redis command GET product:1001 on the replica instance to verify that the key product:1001 with value Laptop has been replicated from the master.
Redis
Hint
Use GET with the key name to check the replicated value.
Practice
(1/5)
1. What is the main purpose of the master-replica architecture in Redis?
easy
A. To copy data from one main server to others for safety and speed
B. To delete data from all servers simultaneously
C. To run multiple unrelated databases on one server
D. To encrypt data on the master server only
Solution
Step 1: Understand the role of master and replicas
The master server holds the original data, and replicas copy this data to keep backups and improve read speed.
Step 2: Identify the main goal of this setup
This setup is mainly for safety (backup) and speed (load distribution).
Final Answer:
To copy data from one main server to others for safety and speed -> Option A
Quick Check:
Master-replica = data copy for safety and speed [OK]
Hint: Master copies data to replicas for safety and speed [OK]
Common Mistakes:
Thinking replicas delete data
Confusing master-replica with encryption
Believing replicas run unrelated databases
2. Which Redis command correctly sets a server as a replica of another?
easy
A. REPLICAOF <port>
B. SETREPLICA <port>
C. SLAVEOF <port>
D. COPYTO <port>
Solution
Step 1: Recall the Redis command for setting a replica
The correct command is SLAVEOF followed by the master's IP and port.
Step 2: Check the options for exact command syntax
Only SLAVEOF <port> uses the correct command SLAVEOF.
Final Answer:
SLAVEOF <master-ip> <port> -> Option C
Quick Check:
Set replica with SLAVEOF command [OK]
Hint: Use SLAVEOF to set replica, not REPLICAOF or others [OK]
Common Mistakes:
Using REPLICAOF instead of SLAVEOF
Trying non-existent commands like SETREPLICA
Confusing COPYTO with replication commands
3. Given this Redis command sequence on a replica server:
SLAVEOF 192.168.1.10 6379
GET user:100
What will happen if the master at 192.168.1.10 is down?
medium
A. The replica will return an error because it can't reach the master
B. The replica will return the last synced value for user:100
C. The replica will become master automatically
D. The replica will delete the user:100 key
Solution
Step 1: Understand replica behavior when master is down
The replica keeps the last synced data even if the master is offline.
Step 2: Predict the GET command result on replica
GET will return the last known value for the key from the replica's local data.
Final Answer:
The replica will return the last synced value for user:100 -> Option B
Quick Check:
Replica serves last synced data if master is down [OK]
Hint: Replica serves cached data if master is unreachable [OK]
Common Mistakes:
Assuming replica errors out when master is down
Thinking replica auto-promotes to master
Believing replica deletes keys on master failure
4. You run SLAVEOF NO ONE on a Redis replica server but it still behaves like a replica. What is the likely problem?
medium
A. The server is still connected to the master and did not switch roles
B. The server needs a restart to apply the change
C. The command was typed incorrectly; it should be SLAVE OF NO ONE
D. SLAVEOF NO ONE only works on master servers
Solution
Step 1: Understand what SLAVEOF NO ONE does
This command tells the server to stop replicating and become a master.
Step 2: Identify why the server still acts as replica
If the server is still connected or replication not stopped properly, it remains a replica.
Final Answer:
The server is still connected to the master and did not switch roles -> Option A
Quick Check:
Server must disconnect from master to become master [OK]
Hint: Ensure replica disconnects from master to become master [OK]
Common Mistakes:
Typing SLAVE OF instead of SLAVEOF
Thinking restart is always needed
Believing SLAVEOF NO ONE only works on masters
5. You want to ensure your Redis setup continues working if the master fails. Which approach best uses master-replica architecture?
hard
A. Use only one replica and manually copy data to it daily
B. Disable replication and rely on backups only
C. Run multiple masters without replicas to balance load
D. Set multiple replicas and configure automatic failover to promote a replica to master
Solution
Step 1: Identify the goal of continuous operation
To keep Redis working if master fails, replicas must be ready to take over automatically.
Step 2: Evaluate options for failover and replication
Set multiple replicas and configure automatic failover to promote a replica to master uses multiple replicas and automatic failover, which is the best practice.
Final Answer:
Set multiple replicas and configure automatic failover to promote a replica to master -> Option D
Quick Check:
Multiple replicas + auto failover = high availability [OK]
Hint: Use multiple replicas with auto failover for master failure [OK]
Common Mistakes:
Relying on manual data copy only
Running multiple masters without replicas
Disabling replication and trusting backups alone
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.