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 scene applications of redis?

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "what are the scene applications of redis". In the daily operation, I believe many people have doubts about the application of redis scenes. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the questions of "what are the scene applications of redis?" Next, please follow the editor to study!

Master-slave mode

The application scenario of master-slave mode is similar to that of master-slave cluster of database. Master-slave mode is often used for read-write separation, backup and other purposes. To put it simply, master-slave mode has multiple nodes, including master nodes and slave nodes. The structure is shown below:

After keeping the connection, the slave node will actively communicate with the master node and send a synchronization request, and then synchronize.

In fact, in the whole process, the main need is data synchronization, there are two main ways of synchronization, that is, full synchronization and incremental synchronization.

Full synchronization: full synchronization is generally used for full replication when the slave node is just connected to the master node. Of course, you can also carry out active full synchronization according to your needs.

Incremental synchronization: Redis incremental replication refers to the process from the write synchronization of the master server to the slave server when the node initializes and starts to work normally. The 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, receives and executes the received write command from the server, and generally uses buffers, queues (first-in, first-out) and other methods to assist incremental synchronization.

Sentinel mode

Sentinel mode is an architecture generated to ensure the high availability of redis. To put it simply, it monitors nodes by building one or more sentinels. If master fails and goes offline, sentinels will vote among them. After 2.8, Raft algorithm is used for master election. In fact, this algorithm is also applied to zookeeper and some network topologies. To put it simply, after the communication node has reached a consensus in the election process, the vote elects master, and then the failover operation is carried out.

Sentinel runs separately in redis as a process, and Sentinels communicate with each other through this process, which is similar to the principle of zookeeper. It is assumed that the structure of a cluster of 6 nodes and 3 Sentinels should be as follows:

So how did the Sentinel monitor the master offline?

Earlier, we also saw that Sentinels detect clusters and monitor each other between Sentinels, but Sentinels do not need to make any configuration, because Sentinels skillfully use master's publish / subscribe mechanism to automatically discover other sentinel nodes that also monitor unified master. There are generally two types of master monitoring:

Subjectively Down (SDOWN for short) refers to the offline judgment made by a single Sentinel instance to the server.

Objective offline (Objectively Down, referred to as ODOWN) refers to the server offline judgment obtained after multiple Sentinel instances make a SDOWN judgment on the same server and communicate with each other through commands. A Sentinel can ask another Sentinel if it thinks a given server has gone offline by sending a command to another server.

Slicing cluster

In the above section, regardless of the redis master-slave, or the highly available sentinel Sentinel mode. All we have done is to ensure that the data is backed up and highly available. So far, our program has been writing data to one redis, and the other redis is just backup. In practice, sharding clusters are commonly used, so why should I emphasize that they are sharding clusters? in fact, the master, slave and sentinels mentioned above are all clusters, but they are all backup clusters, and the actual data is controlled by one machine. The so-called sharding actually distributes different data on different machines according to certain distribution rules.

In redis, our application needs to calculate and access data according to a certain algorithm (consistent hash), so how to realize data slicing in redis? First of all, there are at least three data shards in Redis. Each shard is called master. Assuming that there are N nodes in the whole cluster, then each node maintains a connection and heartbeat with other Nmur1 nodes. The communication between nodes mainly confirms whether the node is alive, the data version of the node, voting for a new master, and so on.

So our final cluster structure is roughly as follows:

At this point, the study of "what are the scenario applications of redis" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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

Servers

Wechat

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

12
Report