0
0
Redisquery~5 mins

Read-only replicas in Redis

Choose your learning style9 modes available
Introduction

Read-only replicas help you get data faster and keep your main database safe by sharing the work of answering read requests.

When many users want to read data at the same time without changing it.
To reduce the load on your main Redis server so it can focus on writing data.
When you want to have backup copies of your data that can be used if the main server fails.
To improve the speed of reading data by placing replicas closer to users in different locations.
Syntax
Redis
replicaof <master_host> <master_port>
Use this command on a Redis server to make it a read-only replica of the master server.
Once set, the replica will copy data from the master and only allow read commands.
Examples
This makes the current Redis server a read-only replica of the master running on localhost at port 6379.
Redis
replicaof 127.0.0.1 6379
This command stops replication and makes the Redis server a master again.
Redis
replicaof no one
Sample Program

This command sets the current Redis server as a read-only replica of the master server at IP 192.168.1.100 on port 6379.

Redis
# On the replica Redis server CLI
replicaof 192.168.1.100 6379

# Now this server will copy data from the master at 192.168.1.100:6379 and only allow read commands.
OutputSuccess
Important Notes

Read-only replicas cannot accept commands that change data, like SET or DEL.

Replicas automatically sync data from the master and stay updated.

You can have many replicas for one master to handle lots of read requests.

Summary

Read-only replicas copy data from a master Redis server to share read load.

They improve performance and provide data safety by offloading reads from the master.

Use the replicaof command to set or remove replication.