redis的复制是异步的,在redis2.8开始,slave阶段性的接受复制流中的信息
一个master可以有多个slave
slave能接受来自其他slave的连接
redis的复制在master端是非阻塞的,在slave端也是非阻塞的,当slave在初始化同步的时候,可以使用老版本的数据集来提供查询。然而,在初始化同步后,老的数据集要被删除,新的数据集要被加载,在这段时间内,slave会阻塞查询。
有的时候,考虑到延时等情况,需要将master上的持久化配置关闭,在slave上持久化,就会有个问题,如果master重启了,那么数据集是空的,会同步到slave上,数据就没有了,需要将master的实例配置成系统在自动重启后,避免自动start。
slave开始连接的时候发送一个PSYNC命令,如果master上有足够的backlog,那么只有差异的数据被发送,否则会发送一个全量的数据,master会启动后台保存进程,并将客户端的请求保存起来,当save完成后,发送到slave磁盘,然后加载,master会将buffer的命令发送到salve,
在2。8开始,master和slave可以不进行全量的复制,
This works by creating an in-memory backlog of the replication stream on the master side. The master and all the slaves agree on a replication offset and a master run ID, so when the link goes down, the slave will reconnect and ask the master to continue the replication. Assuming the master run ID is still the same, and that the offset specified is available in the replication backlog, replication will resume from the point where it left off. If either of these conditions are unmet, a full resynchronization is performed (which is the normal pre-2.8 behavior). As the run ID of the connected master is not persisted to disk, a full resynchronization is needed when the slave restarts.
The new partial resynchronization feature uses the PSYNC command internally, while the old implementation uses the SYNC command. Note that a Redis slave is able to detect if the server it is talking with does not support PSYNC, and will use SYNC instead.
在2。8。18开始,复制不在需要磁盘了
Normally a full resynchronization requires to create an RDB file on disk, then reload the same RDB from disk in order to feed the slaves with the data.
With slow disks this can be a very stressing operation for the master. Redis version 2.8.18 is the first version to have support for diskless replication. In this setup the child process directly sends the RDB over the wire to slaves, without using the disk as intermediate storage.
Diskless replication can be enabled using the repl-diskless-sync configuration parameter. The delay to start the transfer in order to wait more slaves to arrive after the first one, is controlled by the repl-diskless-sync-delay parameter.
只读slave
slave-read-only