Master-replica architecture helps keep data safe and available by copying data from one main server (master) to others (replicas).
0
0
Master-replica architecture in Redis
Introduction
You want to make sure your data is backed up automatically.
You need to handle many users reading data at the same time without slowing down.
You want to keep your app running even if one server stops working.
You want to spread the load so the main server doesn't get too busy.
Syntax
Redis
To set a Redis server as a replica:
SLAVEOF <master-ip> <master-port>
To stop being a replica and become a master again:
SLAVEOF NO ONEThe SLAVEOF command tells a Redis server to copy data from the master server.
Use SLAVEOF NO ONE to make a replica stop copying and become a master.
Examples
This command makes the current Redis server a replica of the master at IP 192.168.1.100 on port 6379.
Redis
SLAVEOF 192.168.1.100 6379
This command makes the current Redis server stop being a replica and become a master.
Redis
SLAVEOF NO ONE
Sample Program
This example sets the current Redis server as a replica of the master on localhost. Then it checks the server role.
Redis
# On replica server terminal SLAVEOF 127.0.0.1 6379 # Now the replica copies data from the master running on localhost port 6379 # To check role: ROLE
OutputSuccess
Important Notes
Replicas only copy data from the master; they do not accept writes directly.
When the master changes data, replicas update automatically to match.
Using replicas can improve read speed by spreading requests across servers.
Summary
Master-replica architecture copies data from one main server to others for safety and speed.
Use SLAVEOF to set a replica and SLAVEOF NO ONE to make it a master again.
Replicas help keep your app working even if the master has problems.