Redis supports master-slave replication and is easy to configure. Master-slave replication implements data backup and redundancy to build a high-availability system. When the master fails to work normally, you can switch the slave to the master.
Redis master-slave replication is easy to configure and use. Master-slave replication allows multiple slave servers to have the same database copies as the master server. The following are some features of redis master-slave replication:
1. The master can have multiple slave instances and only one master instance is allowed.
2. In addition to connecting multiple slave instances to the same master, slave can also be connected to other slave instances to form a graph structure.
3. Master-slave replication does not block the master. That is to say, when one or more slave and master synchronize data for the first time, the master can continue to process the requests sent by the client. On the contrary, slave blocks requests that cannot process the client when synchronizing data for the first time.
4. Master-slave replication can be used to improve the scalability of the system. We can use multiple slave for client read requests. For example, sort operations can be processed using slave. It can also be used for simple data redundancy (different processing separation, similar to MySQL read/write splitting applications)
5. You can disable data persistence on the master. You only need to comment out all the Save configurations in the master configuration file, and then configure data persistence only on the slave.
Principle of redis master-slave Synchronization
After the slave server is configured, slave automatically establishes a connection with the master and sends the sync command. The master will start a background process to save the memory data in snapshot mode, whether it is the first synchronization established connection or the re-connection after the connection is disconnected.
File, and the master process starts to collect new write commands and cache them (these commands on the master will be executed and cached at the same time ). After the background process writes a file, the master sends the file to slave. slave saves the file to the disk and then loads it To the memory for recovery.
The database snapshot is taken to the slave. Then the master will forward the cache command to slave. In addition, the write commands received by the master will be sent to slave through the established connection. The command for synchronizing data from Master to slave is the same as the command sent from client.
Data. When the master and slave are disconnected, slave can automatically establish a new connection. If the master receives synchronous connection commands from multiple slave instances at the same time, only one process is started to write the database image and then sent to all slave instances.
It is easy to configure the slave server. You only need to add the following configuration in the configuration file:
Slaveof 192.168.1.1 6379 # specify the master's IP address and port
Redis master-slave Synchronization