Redis learning, redis

Source: Internet
Author: User

Redis learning, redis
Features of Redis master-slave copy

After the slave is connected to the master, slave sends a SYNC command to the master. After the master receives the command, whether it is the first connection established during synchronization or the reconnection after the connection is closed, the master will enable the BGSAVE operation, start a background process, save a snapshot of the current master memory, and start to save all write commands after BGSAVE is called. After the master generates a snapshot, send the rdb file of the memory snapshot to slave. After the slave receives the rdb file sent by the master, it clears all old data, loads the received rdb file to the memory, and sends the rdb file to the slave, the server Load balancer starts sending the saved write operation logs to the Server Load balancer. The Server Load balancer performs these write operations. At this point, the master and slave data are consistent. After the write log is sent, the master node incrementally sends the write operations to slave to make the master and slave nodes consistent.

Ps: 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 memory snapshot and then sent to all slave instances.

Master write, Slave read Mechanism

Redis master-slave replication achieves data read/write separation through programs, so that the master is responsible for processing some requests, slave is responsible for processing read requests, and slave is responsible for processing more concurrent requests by extending the slave, reduces the load on the master.

Ps: determine the user's read/write requests in the program, send the write request to the master, and send the read Request to the slave for processing.

Redis master-slave copy configuration

Enable master-slave replication. In the simplest way, connect to the slave redis server and execute slaveof

Slaveof 192.168.100.126 6379 # configure host information
Masterauth # If the host has a password set, configure the password
Slave-serve-stale-data yes # configure whether to respond when the slave is synchronizing with the host. If the configuration is yes, the client may read the old data. If the configuration is no, when you request to read data, an error will be reported: SYNC with master in progress.
Slave-read-only yes # Whether the slave is read-only. This configuration is writable and will not be synchronized to the host,
Repl-ping-slave-period 10 # interval between the ping Command sent from the host and the host.
Repl-timeout 60 # host response timeout, which includes transmission timeout, IO timeout, and ping timeout. Note that the timeout must be greater than the preceding interval. Otherwise, a timeout error will always be reported.
Repl-disable-tcp-nodelay no # Whether to disable tcp nodelay. The official recommendations for this configuration are:
# By default we optimize for low latency, but in very high traffic conditions
# Or when the master and slaves are running hops away, turning this to "yes" may
# Be a good idea.
# By default, we aim to optimize low latency, but in high transmission conditions or the master and slave hosts are distributed out of many hops. We recommend disabling tcp-nodelay.
Slave-priority 100 # If the master node cannot work normally, one slave with the smallest priority value will be promoted to the master node among multiple slave instances. If the priority value is 0, the master node cannot be upgraded.

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.