Replication in Redis means copying data from one Redis server (called master) to one or more Redis servers (called replicas). This helps with data backup and load sharing.
Click to reveal answer
beginner
How do you configure a Redis server as a replica?
To configure a Redis server as a replica, you use the command REPLICAOF <master-ip> <master-port> in the replica's configuration or at runtime.
Click to reveal answer
intermediate
What happens when a Redis replica connects to its master?
When a replica connects to its master, it performs a synchronization. The master sends a snapshot of the data, and then streams any new changes to keep the replica updated.
Click to reveal answer
intermediate
Can a Redis replica accept write commands?
By default, Redis replicas are read-only and do not accept write commands. This prevents data conflicts and keeps data consistent with the master.
Click to reveal answer
advanced
What is the role of the replica-serve-stale-data setting?
The replica-serve-stale-data setting controls if a replica serves data when it is disconnected from the master. If set to yes, it serves old data; if no, it returns errors until reconnected.
Click to reveal answer
Which command sets a Redis server as a replica of another?
AREPLICAOF <master-ip> <master-port>
BMASTEROF <replica-ip> <replica-port>
CSLAVEOF <master-ip> <master-port>
DCOPYDATA <master-ip> <master-port>
✗ Incorrect
The correct command is REPLICAOF to configure a Redis server as a replica.
What does a Redis replica do when it first connects to the master?
ADeletes all its data
BSends its data to the master
CBecomes the new master
DSynchronizes by receiving a snapshot from the master
✗ Incorrect
The replica synchronizes by receiving a snapshot of the master's data.
By default, can Redis replicas accept write commands?
AYes, always
BOnly if configured
CNo, they are read-only
DOnly during synchronization
✗ Incorrect
Redis replicas are read-only by default to avoid data conflicts.
What does the replica-serve-stale-data setting control?
AWhether replicas serve data when disconnected from master
BWhether replicas accept writes
CThe number of replicas allowed
DThe master IP address
✗ Incorrect
It controls if replicas serve old data when disconnected from the master.
What is the main benefit of using replication in Redis?
AFaster writes on the master
BData backup and load sharing
CAutomatic data deletion
DEncrypting data
✗ Incorrect
Replication helps with data backup and sharing the load for reads.
Explain how to set up a Redis replica and what happens during synchronization.
Think about the commands and the data flow between master and replica.
You got /4 concepts.
Describe the purpose of the replica-serve-stale-data setting in Redis replication.
Consider what happens if the replica loses connection to the master.
You got /3 concepts.
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
Step 1: Understand replication concept
Replication means copying data from one server (master) to others (replicas) automatically.
Step 2: Identify the main goal
This copying helps keep data safe and allows multiple servers to serve read requests.
Final Answer:
To copy data from a master server to replicas automatically -> Option C
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
Step 1: Recall Redis replication commands
Redis uses the command REPLICAOF (formerly SLAVEOF) to set a server as a replica.
Step 2: Check command correctness
Only REPLICAOF accepts master IP and port to configure replication.
Final Answer:
REPLICAOF <master_ip> <master_port> -> Option A
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
Step 1: Understand replica-read-only setting
Setting replica-read-only to yes means the replica will not accept writes from clients.
Step 2: Identify behavior of replica
The replica only allows read commands and rejects any write commands to keep data consistent with master.
Final Answer:
The replica rejects write commands and only allows reads -> Option A
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
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.
Step 2: Verify command correctness
The command replicaof with IP and port is correct; no 'start' keyword is needed.
Final Answer:
The master IP or port is incorrect or unreachable -> Option B
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
Step 1: Understand replica-read-only option
Setting replica-read-only to no allows writes on the replica, useful during maintenance.
Step 2: Combine with replication setup
Using replicaof configures replication; setting replica-read-only no allows writes while still replicating.
Final Answer:
Use replicaof <master_ip> <master_port> and set replica-read-only no -> Option D
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 unknownstrongwhile earning +1 Grip toward your certificate.