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: