Redis master-slave replication principle:
By passing this RDB file or aof file to the slave server, the slave server reloads the Rdb file to realize the function of replication!
Copy the words: The master server can have multiple slave servers!!! Not only this from the server can also have from the server, can be made into a star-like structure!
Copy the words will not block the process, the same fork a sub-process to do!
The principle of replication:
When a slave server is established, the server will want to send a sync command from the primary server, and the master server will execute bgsave after receiving the Sync command.
Then save to the Rdb file and then send it to the slave server! Receive the Rdb file and load it into memory!
Delta is not supported at the earliest, and increments are supported after 2.8!
Redis Master-Slave configuration:
The configuration is simple:
I want to put: 192.168.11.241 6379 as a 192.168.11.240 from only need one command
192.168.11.241:6379> slaveof 192.168.11.240 6379ok192.168.11.241:6379> info# Replicationrole:slavemaster_host:192.168.11.240master_port:6379master_link_status:upmaster_last_io_seconds_ago : 1master_sync_in_progress:0slave_repl_offset:15slave_priority:100slave_read_only:1connected_slaves:0master_ Repl_offset:0repl_backlog_active:0repl_backlog_size:1048576repl_backlog_first_byte_offset:0repl_backlog_ Histlen:0 then go to the top of the master to see:# redis-cli -h 192.168.11.240 192.168.11.240:6379> info# Replicationrole:masterconnected_slaves:1slave0:ip=192.168.11.241,port=6379,state=online,offset=456,lag=1master _repl_offset:456repl_backlog_active:1repl_backlog_size:1048576repl_backlog_first_byte_offset:2repl_backlog_ histlen:455 wrote an instruction in the Lord: 192.168.11.240:6379> set key hello,worldok on the view from the:192.168.11.241:6379> get key "Hello,world" #可以看到主从已经同步从2.61! From is read-only 192.168.11.241:6379> set key1 33033 (error) &NBsp Readonly you can ' t write against a read only slave.192.168.11.241:6379 > #现实工作场景中, write and read is 1:10 of the ratio, we can set a master much from doing read and write separation!
This article is from the "Ask Heaven" blog, please make sure to keep this source http://79076431.blog.51cto.com/8977042/1755302
Redis Master-Slave