Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the methods to implement the high availability mechanism of redis

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

What are the ways to implement the high availability mechanism of redis? In view of this problem, this article gives the corresponding analysis and answers, hoping to help more friends who want to solve this problem to find a more simple and feasible way.

Ensuring the high availability of redis mechanism requires the support of redis master-slave replication, redis persistence mechanism, Sentinel mechanism, keepalived and so on.

The role of master-slave replication: data backup, read-write separation, distributed cluster, high availability, downtime fault tolerance mechanism and so on.

Principle of redis master-slave replication

First of all, master-slave replication needs to be divided into two roles: master (master) and slave (slave). Note: only one master is supported in redis, unlike Mysql and Nginx master-slave replication.

1. The replication function of redis is to support data synchronization between multiple databases. One is the master database (master) and the other is the slave database (slave). When the write operation occurs, the master database can automatically synchronize the data to the slave database, while the slave database is generally read-only and receives the data synchronized from the master database. A master database can have multiple slave databases, while a slave database can only have one master database.

2. Through the replication function of redis, the read and write separation of the database can be realized, and the load capacity of the server can be improved. The master database is mainly for write operations, while the slave database is responsible for read operations.

The process of master-slave replication synchronization: see the following figure

Redis master-slave replication can be divided into full synchronization and incremental synchronization according to whether it is full or not.

Full Redis replication usually occurs during the Slave initialization phase, when Slave needs to make a copy of all the data on the Master.

Full synchronization process:

1: when a slave database is started, a sync command is sent to the master database

2: after receiving the sync command, the master database starts to save the snapshot in the background (performing rdb operations) and records all subsequent write operations with the cache.

3: when the snapshot of the master server is saved, redis sends the snapshot file to the slave database.

4: when a snapshot file is received from the database, all old data is discarded and the snapshot received is loaded.

5: after the master server snapshot is sent, it begins to send the write command in the buffer to the slave server.

6: finish loading the snapshot from the server, receive command requests, and execute write commands from the autonomous server buffer.

The process of incremental synchronization:

Redis incremental replication refers to the process of write synchronization to slave server that occurs on the master server when slave initialization begins to work normally.

The main process of incremental replication is that every time the master server executes a write command, it sends the same write command to the slave server, and receives and executes the received write command from the server.

Choice of full and incremental synchronization of Redis master-slave replication:

When the master and slave servers are just connected, full synchronization will be carried out first, and incremental synchronization will be carried out after the full synchronization is over. Of course, slave can initiate full synchronization at any time if necessary. The redis policy is that, in any case, incremental synchronization will be attempted first, and if unsuccessful, full synchronization from the slave is required.

How to configure redis master-slave replication?

Modify the redis.conf file in the slave server redis/conf modify the IP address and port number of the IP and port of the master server slaveof 10.211.55.9 6379 masterauth 123456Murray-if the master redis server is configured with a password, you need to configure

You only need to configure the redis.conf of the slave server, not the master server. To verify whether it is successful, you can log in to the main server redis-cli client first and enter info.

If role shows master and slave0 can display ip of slave server normally, it means master-slave service configuration is successful, master-slave replication configuration is successful, and read-write separation is achieved at the same time, do you believe it? Why don't you try and see if your slave server can still write?

The answer is: no. Only read operations from the server!

This is the end of the way to achieve the high availability mechanism of redis. I hope the above content can be helpful to you and learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report