本文内容为 http://redis.io/commands/slaveof 的翻译、注解、例子扩充及其它修改。感谢 Redis 作者 Antirez 为开源社区作出的贡献,本文保证最新、最准、最全以表示对其的敬意。欢迎留言纠错、提示更新或支持。
SLAVEOF host port

当前命令可以在从实例(Slave)执行时动态(On the fly)改变复制同步(Replication)机制的设置。

The SLAVEOF command can change the replication settings of a slave on the fly.

如果一个 Redis 服务端(Server)已经是一个从实例,那么命令 SLAVEOF NO ONE 将会关闭复制机制,将当前服务端转变为一个主实例(Master)。如果按正常的 SLAVEOF hostname port 格式调用,当前服务端将会变成另一个由指定主机名(Hostname)及端口号(Port)确定的服务端的从实例。

If a Redis server is already acting as slave, the command SLAVEOF NO ONE will turn off the replication, turning the Redis server into a MASTER. In the proper form SLAVEOF hostname port will make the server a slave of another server listening at the specified hostname and port.

如果一个服务端已经是某个主实例的一个从实例,命令 SLAVEOF hostname port 将会停止对原先主实例的复制同步,而转为对新的主实例开启同步(Synchronization)机制,且抛弃掉(Discard)旧的数据库。

If a server is already a slave of some master, SLAVEOF hostname port will stop the replication against the old server and start the synchronization against the new one, discarding the old dataset.

SLAVEOF NO ONE 将会停止复制同步(Replication)机制,将当前服务端转变为一个主实例,但是不会丢弃已复制数据。因此,如果一个旧主实例停止工作,这个时候可以将其下的某个从实例转变成主实例,同时设置应用程序使用该新主实例。之后,如果有其它的 Redis 服务端(Server)完成修复,可以将其配置为一个从实例。

The form SLAVEOF NO ONE will stop replication, turning the server into a MASTER, but will not discard the replication. So, if the old master stops working, it is possible to turn the slave into a master and set the application to use this new master in read/write. Later when the other Redis server is fixed, it can be reconfigured to work as a slave.