从数据库1同步到缓存:
- 127.0.0.1:6380> keys *
- 1) "test02"
- 2) "c"
- 3) "d"
- 4) "a"
- 5) "test"
- 6) "kebo"
- 7) "slavetest"
- 8) "b"
- 9) "redisfast"
- 127.0.0.1:6380> get slavetest
- "0851"
重启从数据库2:
- 34855:S 26 Aug 2019 13:34:39.561 * DB loaded from disk: 0.000 seconds
- 34855:S 26 Aug 2019 13:34:39.561 * Before turning into a replica, using my master parameters to synthesize a cached master: I may be able to synchronize with the new master with just a partial transfer.
- 34855:S 26 Aug 2019 13:34:39.561 * Ready to accept connections
- 34855:S 26 Aug 2019 13:34:39.561 * Connecting to MASTER 127.0.0.1:6379
- 34855:S 26 Aug 2019 13:34:39.561 * MASTER <-> REPLICA sync started
- 34855:S 26 Aug 2019 13:34:39.561 * Non blocking connect for SYNC fired the event.
- 34855:S 26 Aug 2019 13:34:39.561 * Master replied to PING, replication can continue...
- 34855:S 26 Aug 2019 13:34:39.562 * Trying a partial resynchronization (request d41f950be7593a93620b1fd872b7552668f0b355:888).
- 34855:S 26 Aug 2019 13:34:39.562 * Successful partial resynchronization with master.
- 34855:S 26 Aug 2019 13:34:39.562 * MASTER <-> REPLICA sync: Master accepted a Partial Resynchronization.
从库启动后,加载当地数据,开始向主数据库举办哀求同步,这里同步出发点是按照从数据库的offset开始。
主库信息:
- 34781:M 26 Aug 2019 13:24:06.701 * Synchronization with replica 127.0.0.1:6382 succeeded
- 34781:M 26 Aug 2019 13:29:45.037 # Connection with replica 127.0.0.1:6382 lost.
- 34781:M 26 Aug 2019 13:34:39.562 * Replica 127.0.0.1:6382 asks for synchronization
- 34781:M 26 Aug 2019 13:34:39.562 * Partial resynchronization request from 127.0.0.1:6382 accepted. Sending 56 bytes of backlog starting from offset 888.
当从数据库从头连上主数据库时,从数据库会通过PSYNC呼吁将本身的复制偏移量offset发送给主数据库,主数据库会按照这个复制偏移量来抉择对从数据库执行何种同步操纵。以到达全部数据库的偏移量同等。
- 127.0.0.1:6379> info replication
- # Replication
- role:master
- connected_slaves:2
- slave0:ip=127.0.0.1,port=6380,state=online,offset=1139,lag=1
- slave1:ip=127.0.0.1,port=6382,state=online,offset=1139,lag=1
- master_replid:d41f950be7593a93620b1fd872b7552668f0b355
- master_replid2:0000000000000000000000000000000000000000
- master_repl_offset:1139
- second_repl_offset:-1
- repl_backlog_active:1
- repl_backlog_size:1048576
- repl_backlog_first_byte_offset:1
- repl_backlog_histlen:1139
总结:
Redis在主从数据库之间的复制是异步的,这意味着,主数据库执行完客户端哀求的呼吁后会当即将呼吁发送给哀求的客户端,并同步到从数据库,而不会守候从数据库吸取到呼吁后再返回给客户端,因此该环境就会存在必然的数据纷歧致性风险,也就是Redis不担保强同等性,而是通过从库计策追赶与主数据库的数据差别,以保障主从状态一向。在Redis中也可以配置参数来强行让从库数据同步后,主库才气继承写入,这样的设置对主库会见要求较高,因此会影响主库的机能。
在主从同步中,假如呈现数目差别较大,Redis会按照从库的offset举办选择全量、增量的规复。 (编辑:湖南网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|