I. Redis's replication
Advantages: Read/write separation
The following list clearly explains the features and benefits of Redis replication.
1). The same master can synchronize multiple slaves.
2). Slave can also accept other slaves connection and synchronization requests, which can effectively load the sync pressure of master. So we can treat Redis's replication architecture as a graph structure.
3). Master Server provides services for slaves in a non-blocking manner. So during Master-slave synchronization, the client can still submit queries or modify requests.
4). Slave Server also completes data synchronization in a non-blocking manner. During synchronization, if a client submits a query request, REDIS returns the data before synchronization.
5). In order to load the read operation pressure of master, the slave server can provide a read-only service to the client, and the write service must still be completed by master. Even so, the scalability of the system has been greatly improved.
6). Master can leave the data save operation to slaves to complete, thus avoiding the need to have a separate process in master to complete the operation.
Second, the working principle of replication
After the slave is started and connected to master, it will actively send a sync command. Master will then start the background disk process and collect all the received commands to modify the dataset, and master will transfer the entire database file to slave to complete a full synchronization once the background process has finished executing. The slave server then disks and loads the database file data into memory after it receives it. After that, Master continues to pass all the modified commands that have been collected, and the new modification commands to Slaves,slave will execute these data modification commands at this time to achieve final data synchronization.
If the link between master and slave appears to be disconnected, slave can automatically reconnect master, but once the connection is successful, a full synchronization will be performed automatically.
Master saves the Rdb file through a child process, so master can still handle the client request without being blocked, but this also causes the "key space" to change during the time the Rdb file is saved (such as receiving a client request, executing "set name Diaocow" command), so in order to ensure the consistency of data synchronization, master will save the Rdb file during the storage of these possible changes to the database "key space" command, and then put it in the reply list of each slave, when the Rdb file is sent out master will send the contents of these replies list , and after that, if the database changes, master will still append the changed command to the reply list and send it to slave, which will guarantee the consistency of the master and slave data!
Third, how to configure replication
1. Temporary
Execute the command on the Slave_b server: slaveof 127.0.0.1 6379 The above method only guarantees that after the slaveof command is executed, B becomes the slave of a, and once the service (B) restarts, the replication relationship between them terminates. 2, Permanent: Modify slave redis.confslaveof IP Port--set the IP and port of master if the primary database has a password set, you need to set the password for the primary database through the Masterauth parameter in the configuration file from the data.
Iv. Redis Master-slave Replication considerations
If you use master-slave replication, Make sure that master activates the persistence , or that it does not restart automatically after the outage . Because slave is a full backup of Master, slave is also cleared if master restarts with an empty data set.
Reference: http://www.cnblogs.com/stephen-liu74/archive/2012/02/23/2364717.html
Other information: http://blog.csdn.net/pi9nc/article/details/17735653
Redis Master-slave replication