8. Master-slave replication of redis Study Notes

Source: Internet
Author: User
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.
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.
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.

The following describes the process of master-slave replication.
After the slave server is configured, slave establishes a connection with the master and sends the sync command. The master will start a background process to save database snapshots to files, whether it is the first synchronization established connection or the re-connection after the connection is disconnected, at the same time, the master process starts to collect new write commands and cache them. After the background process completes file writing, the master sends the file to slave. slave saves the file to the disk and then loads it To the memory to restore the database snapshot to 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 in the same protocol format as the command sent from client. 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.

configuring the slave server is simple. You only need to add the following configuration in the configuration file
slaveof 192.168.1.1 6379 # specify the master IP address and port

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.