Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Redis Slaveof Command

Redis Slaveof Command

Redis Server

The Redis Slaveof command can turn the current server into a replica (slave) of the specified server.

If the current server is already a replica of some master server, executing SLAVEOF host port will stop the current server's synchronization with the old master, discard the old dataset, and begin synchronizing with the new master.

In addition, executing the command SLAVEOF NO ONE on a replica will disable the replica's replication function and turn it back from a replica into a master; the previously synchronized dataset will not be discarded.

Taking advantage of the property that "SLAVEOF NO ONE does not discard the synchronized dataset", when the master fails, you can use the replica as the new master, achieving uninterrupted operation.

Syntax

The basic syntax of the redis Slaveof command is as follows:



redis 127.0.0.1:6379> SLAVEOF host port  

Available Version

= 1.0.0

Return Value

Always returns OK.

Example



redis 127.0.0.1:6379> SLAVEOF 127.0.0.1 6379

OK



redis 127.0.0.1:6379> SLAVEOF NO ONE

OK

Redis Server