0
0
Redisquery~5 mins

Replication configuration in Redis

Choose your learning style9 modes available
Introduction

Replication helps copy data from one Redis server to another. This keeps data safe and allows sharing work between servers.

You want a backup server that always has the latest data.
You want to spread read requests to multiple servers to improve speed.
You want to keep data safe if one server stops working.
You want to update data on one server and have others copy it automatically.
Syntax
Redis
slaveof <masterip> <masterport>

This command sets the current Redis server as a replica (slave) of the master server.

Use replicaof instead of slaveof in Redis 5.0 and later for clearer naming.

Examples
Make this Redis server a replica of the master at IP 192.168.1.100 on port 6379.
Redis
replicaof 192.168.1.100 6379
Stop replication and make this server a master again.
Redis
replicaof no one
Sample Program

This command configures the current Redis server to replicate data from the master server running on the same machine at port 6379.

Redis
# Connect to Redis server and run:
replicaof 127.0.0.1 6379

# This makes the current server copy data from the master at localhost port 6379.
OutputSuccess
Important Notes

Replication is asynchronous, so replicas may be slightly behind the master.

Use replicaof no one to stop replication and promote the replica to master.

Summary

Replication copies data from a master Redis server to replicas.

Use replicaof <ip> <port> to set replication.

Use replicaof no one to stop replication.