Redis Master/Slave Configuration

Source: Internet
Author: User

Redis Master/Slave Configuration

Recommended reading:

Redis installation and configuration tutorial and phpredis extension installation test
Redis command reference Replication)

1. Introduction
Reference from https://redis.readthedocs.org/en/latest/topic/replication.html below

Redis supports the simple and easy-to-use master-slave replication function, which enables the slave server to become a precise replica of the master server.

2. Principles

Whether it is a first connection or a new connection, when a slave server is established, the slave server will send a SYNC command to the master server.

The master server that receives the SYNC command will start to execute BGSAVE and save all newly executed write commands to a buffer zone during the execution of the Save operation.

After BGSAVE is completed, the master server sends the. rdb file obtained from the save operation to the slave server, receives the. rdb file from the server, and loads the data in the file into the memory.

Then, the master server sends all the content accumulated in the write command buffer to the slave server in the format of the Redis command protocol.

You can use the telnet command to verify the synchronization process: first, connect to a Redis server that is processing the command request, and then send the SYNC command to it. After a while, you will see that the telnet session receives a large data segment from the server (. rdb file), and then you will see that all the write commands executed on the server will be re-sent to the telnet session.

Even if multiple slave servers send SYNC requests to the master server at the same time, the master server only needs to execute the BGSAVE command once to process all these slave server synchronization requests.

The slave server can automatically reconnect when the Master/Slave servers are disconnected. Before Redis 2.8, full resynchronization is always performed on the slave server after the disconnection) but starting from Redis 2.8, the slave server can choose whether to perform full or partial Synchronization Based on the master server ).

3. Practice
Note: The following Master/Slave servers are configured on the same server.

1. Start the master server and slave server, and listen to port 6379 and port 6380 respectively:

 

2. Modify the slave server:

 

3. Restart the slave server. You can compare the master and slave data to achieve master-slave replication:

Install and test Redis in Ubuntu 14.04

Redis cluster details

Install Redis in Ubuntu 12.10 (graphic explanation) + Jedis to connect to Redis

Redis series-installation, deployment, and maintenance

Install Redis in CentOS 6.3

Learning notes on Redis installation and deployment

Redis. conf

This article permanently updates the link address:

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.