0
0
Redisquery~5 mins

REPLICAOF command in Redis

Choose your learning style9 modes available
Introduction

The SLAVEOF command tells a Redis server to copy data from another Redis server. This helps keep data the same on multiple servers.

You want to create a backup server that copies data from the main server.
You need to spread read requests to reduce load on the main server.
You want to keep data safe by having a copy on another machine.
You want to test changes on a copy without affecting the main data.
Syntax
Redis
SLAVEOF <host> <port>
SLAVEOF NO ONE

Use SLAVEOF <host> <port> to start copying from another server.

Use SLAVEOF NO ONE to stop copying and make the server standalone.

Examples
This makes the current Redis server copy data from the server at IP 192.168.1.100 on port 6379.
Redis
SLAVEOF 192.168.1.100 6379
This stops replication and makes the server independent again.
Redis
SLAVEOF NO ONE
Sample Program

First, the server starts copying data from a Redis server running locally on port 6380. Then, it stops copying and becomes standalone.

Redis
SLAVEOF 127.0.0.1 6380
SLAVEOF NO ONE
OutputSuccess
Important Notes

Replication is asynchronous, so data may not be exactly the same at every moment.

Use SLAVEOF NO ONE carefully to avoid data loss if the server was only a replica.

Summary

SLAVEOF sets a Redis server to copy data from another server.

Use SLAVEOF NO ONE to stop replication and make the server standalone.

This helps with backups, load distribution, and data safety.