High-availability Redis distributed cache system and control method thereof

By deploying the Redis master-slave sentry architecture and automatic disaster recovery module in the Redis distributed cache system, data loss and business interruption caused by Redis node failures are solved, and high availability and strong data consistency are achieved.

CN119884176APending Publication Date: 2025-04-25CHINA TELECOM CLOUD TECH CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411654109.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-18
Publication Date
2025-04-25

AI Technical Summary

Technical Problem

Redis node failures can lead to data loss and business interruption, and there are data inconsistencies in the highly available Redis deployment architecture. Recovery requires a lot of manual setup and intervention, limiting its availability and automation level.

Method used

It provides a highly available Redis distributed cache system and its control method. By deploying Redis master nodes, Redis slave nodes and Redis sentinel nodes in the availability zone of the target cache area, the coordinator and sentinel modules elect the coordinator nodes in the Redis master node, and based on the read and write command requests sent by the client, the coordinator nodes are used for data synchronization and replication to achieve strong data consistency. The automatic disaster recovery recovery module obtains the node status data of the Redis sentry node and performs disaster recovery recovery to ensure that the highly available Redis distributed cache system provides services normally when facing failures or disasters.

Benefits of technology

It avoids data loss and service interruption caused by Redis node failure, realizes the high availability and stability of the highly available Redis distributed cache system, and ensures strong data consistency and automated disaster recovery capabilities.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119884176A_ABST
    Figure CN119884176A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of computers, and discloses a high-availability Redis distributed cache system and a control method thereof, and the method comprises the steps: deploying a Redis master node, a Redis slave node and a Redis sentry node in an available region of a target cache region through a Redis master-slave sentry module; electing a coordinator node in the Redis main node through the coordinator and the sentry module, and carrying out data synchronous copying by utilizing the coordinator node based on a read-write command request sent by the client to obtain a read-write execution feedback result; and acquiring node state data of the Redis sentinel node in the read-write execution process through an automatic disaster recovery module, and carrying out disaster recovery based on the node state data of the Redis sentinel node. According to the method and the device, the problems of data loss and service interruption caused by faults of the Redis nodes are avoided, and high availability and stability of the high-availability Redis distributed cache system are realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a high-availability Redis distributed cache system and a control method thereof. Background Art

[0002] With the continuous development of the Internet, Redis (Remote Dictionary Server) database has become a core component of many online applications and services. Redis's high performance and memory storage features make it the preferred solution for data caching and real-time data analysis.

[0003] However, the failure of Redis nodes may lead to data loss and business interruption, which is an unacceptable challenge for applications that rely on Redis. In addition, the high-availability Redis deployment architecture has the problem of data inconsistency, which may cause information loss during failure and disaster recovery. On the other hand, recovery also requires a lot of manual settings and intervention, which limits its availability and automation. Summary of the invention

[0004] In view of this, the present invention provides a high-availability Redis distributed cache system and a control method thereof to solve the problem of data loss and business interruption caused by failure of Redis nodes.

[0005] In a first aspect, the present invention provides a control method for a high-availability Redis distributed cache system, the high-availability Redis distributed cache system comprising: a Redis master-slave sentinel module, a coordinator and a sentinel module, and an automatic disaster recovery module, the Redis master-slave sentinel module, the coordinator and the sentinel module, and the automatic disaster recovery module are connected in sequence, and the coordinator and the sentinel module are connected to a client; the method comprises:

[0006] Deploy Redis master nodes, Redis slave nodes, and Redis sentinel nodes in the availability zone of the target cache area through the Redis master-slave sentinel module; one Redis master node is connected to multiple Redis slave nodes, and the Redis master node corresponds to the Redis sentinel node one by one;

[0007] The coordinator node is elected in the Redis master node through the coordinator and sentinel modules, and based on the read and write command requests sent by the client, the coordinator node is used to synchronize and replicate data to obtain the read and write execution feedback results;

[0008] The node status data of the Redis sentinel node during the read and write execution process is obtained through the automatic disaster recovery module, and disaster recovery is performed based on the node status data of the Redis sentinel node.

[0009] The present embodiment provides a control method for a high-availability Redis distributed cache system, which deploys Redis master nodes, Redis slave nodes and Redis sentinel nodes in an available zone. The coordinator and sentinel modules elect a coordinator node in the Redis master node, and use the coordinator node to synchronize and replicate data based on the read and write command requests sent by the client. When the Redis master node fails or is unavailable, the Redis slave node upgraded to the Redis master node will not lose data, ensuring the strong consistency of data of the available nodes. The automatic disaster recovery module performs disaster recovery based on the node status data of the Redis sentinel node, ensuring that the high-availability Redis distributed cache system provides services normally in the face of failures or disasters, avoiding the problem of data loss and business interruption caused by the failure of the Redis node, and achieving high availability and stability of the high-availability Redis distributed cache system.

[0010] In an optional implementation, a coordinator node is elected in the Redis master node through the coordinator and sentinel modules, and based on the read and write command requests sent by the client, the coordinator node is used to perform data synchronization replication to obtain read and write execution feedback results, including:

[0011] Obtain the preset election strategy. The coordinator and sentinel modules elect the coordinator node in the Redis master node based on the preset election strategy, and build a synchronization set based on the connection relationship between the coordinator node and the Redis master node.

[0012] The coordinator and sentinel modules send read and write command requests to the coordinator node;

[0013] The coordinator node sends the write command request in the read and write command request to the Redis master node and the Redis slave node for data synchronization replication, receives the first execution feedback result after the data synchronization replication, and sends the first execution feedback result to the client through the coordinator and sentinel modules;

[0014] The coordinator node polls and distributes the read command requests in the read and write command requests to the Redis master nodes in the synchronization set;

[0015] The Redis master node executes the read command request, obtains the second execution feedback result, and sends the second execution feedback result to the client through the coordinator node and the coordinator and sentinel modules in sequence.

[0016] The present embodiment provides a control method for a high-availability Redis distributed cache system, which builds a synchronization set through the connection relationship between the coordinator node and the Redis master node, laying a foundation for the subsequent data synchronization and replication between the coordinator node and the Redis master node; and the coordinator node sends the write command request in the read and write command request to the Redis master node and the Redis slave node for data synchronization and replication, thereby realizing the synchronization and replication of data between the coordinator node, the Redis master node and the Redis slave node, ensuring strong data consistency and avoiding data loss; finally, in the process of processing the client read command request, the coordinator node polls all data synchronized Redis master nodes to process the read command request, so that the read command request has load balancing capability.

[0017] In an optional implementation, the coordinator node sends the write command request in the read and write command request to the Redis master node and the Redis slave node for data synchronization replication, receives the first execution feedback result after the data synchronization replication, and sends the first execution feedback result to the client through the coordinator and sentinel modules, including:

[0018] The coordinator node distributes the write command request to the Redis master node in the synchronization set;

[0019] Execute the write command request through the Redis master node. When the Redis master node executes successfully, it distributes the write command request to the Redis slave nodes in the data synchronization state;

[0020] The Redis slave node executes the write command request and sends the Redis slave node execution result to the Redis master node;

[0021] The Redis master node receives confirmation data sent by the Redis slave node in the data synchronization state, and sends a first execution feedback result to the coordinator node based on the confirmation data;

[0022] The coordinator node sends the first execution feedback result to the client.

[0023] The present embodiment provides a control method for a high-availability Redis distributed cache system, in which a coordinator node performs data synchronization replication with a data-synchronized Redis master node, and a Redis master node performs data synchronization replication with a data-synchronized Redis slave node, thereby ensuring that all data-synchronized nodes in the high-availability Redis distributed cache system maintain strong data consistency with the coordinator node, retaining multiple redundant copies of consistent data, avoiding infinite blocking caused by disconnection between Redis master and slave nodes when the Redis master node replicates synchronously with all Redis slave nodes, and improving the high availability of the high-availability Redis distributed cache system.

[0024] In an optional implementation, the Redis master node receives confirmation data sent by the Redis slave node in a data synchronization state, and sends a first execution feedback result to the coordinator node based on the confirmation data, including:

[0025] If the confirmation data are all successful execution data, the Redis master node sends the first execution feedback result to the coordinator node based on the successful execution data;

[0026] Alternatively, if it is confirmed that there is execution failure data in the data, the Redis master node sends a rollback command to the Redis slave node.

[0027] The present embodiment provides a control method for a high-availability Redis distributed cache system, which performs different feedback by confirming data, and when the execution fails, the Redis master node sends a rollback command to the Redis slave node, so that the data consistency is always maintained between the coordinator node and the Redis master node for data synchronization, as well as between the Redis master node and the Redis slave node.

[0028] In an optional implementation, the node status data of the Redis sentinel node during the read and write execution process is obtained through the automatic disaster recovery module, and disaster recovery is performed based on the node status data of the Redis sentinel node, including:

[0029] The automatic disaster recovery module determines the number of surviving Redis sentinel nodes based on the node status data of the Redis sentinel nodes;

[0030] Compare the number of surviving Redis sentinel nodes with the preset number; the preset number is half of the total number of Redis sentinel nodes;

[0031] If the number of surviving Redis sentinel nodes is less than the preset number, the control coordinator and sentinel modules will re-elect the coordinator node and use the re-elected coordinator node to perform data synchronization and replication.

[0032] The present embodiment provides a control method for a high-availability Redis distributed cache system. When the automatic disaster recovery module monitors that more than half of the Redis sentinel nodes have failed or suffered a disaster, the recalculation total number function of the Redis sentinel nodes is called, so that the remaining Redis sentinel nodes can still normally elect a new coordinator node, thereby ensuring the availability of the high-availability Redis distributed cache system and enabling the automatic disaster recovery module to have the maximum automatic disaster recovery capability. In addition, the coordinator node re-elected by the coordinator and sentinel modules belongs to the Redis master node in the synchronization set, thereby ensuring the data consistency of the new coordinator node and avoiding data loss.

[0033] In an optional implementation, obtaining node status data of the Redis sentinel node during the read and write execution process through the automatic disaster recovery module, and performing disaster recovery based on the node status data of the Redis sentinel node, further comprising:

[0034] If the number of surviving Redis sentinel nodes is greater than the preset number, or the number of surviving Redis sentinel nodes is zero, a monitoring alarm message is sent to the client.

[0035] The present embodiment provides a control method for a high-availability Redis distributed cache system, which realizes timely recovery of the high-availability Redis distributed cache system by sending monitoring alarm information to the client when the number of surviving Redis sentinel nodes is greater than a preset number or the number of surviving Redis sentinel nodes is zero.

[0036] In a second aspect, the present invention provides a highly available Redis distributed cache system, the system comprising: a Redis master-slave sentinel module, a coordinator and sentinel module and an automatic disaster recovery module, the Redis master-slave sentinel module, the coordinator and sentinel module and the automatic disaster recovery module are connected in sequence, and the coordinator and sentinel module are connected to a client;

[0037] The Redis master-slave sentinel module is used to deploy Redis master nodes, Redis slave nodes, and Redis sentinel nodes in the availability zone of the target cache area; one Redis master node is connected to multiple Redis slave nodes, and the Redis master node corresponds to the Redis sentinel node one by one;

[0038] The coordinator and sentinel modules are used to elect the coordinator node in the Redis master node, and based on the read and write command requests sent by the client, use the coordinator node to perform data synchronization replication and obtain the read and write execution feedback results;

[0039] The automatic disaster recovery module is used to obtain the node status data of the Redis sentinel node during the read and write execution process, and perform disaster recovery based on the node status data of the Redis sentinel node.

[0040] In a third aspect, the present invention provides a computer device, comprising: a memory and a processor, the memory and the processor being communicatively connected to each other, the memory storing computer instructions, and the processor executing the computer instructions to execute the control method of the high-availability Redis distributed cache system of the first aspect or any corresponding embodiment thereof.

[0041] In a fourth aspect, the present invention provides a computer-readable storage medium having computer instructions stored thereon, the computer instructions being used to enable a computer to execute a control method for a high-availability Redis distributed cache system according to the first aspect or any corresponding embodiment thereof.

[0042] In a fifth aspect, the present invention provides a computer program product, including computer instructions, which are used to enable a computer to execute the control method of a high-availability Redis distributed cache system of the above-mentioned first aspect or any corresponding embodiment thereof. BRIEF DESCRIPTION OF THE DRAWINGS

[0043] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0044] Figure 1 This is a structural block diagram of a high-availability Redis distributed cache system according to an embodiment of the present invention;

[0045] Figure 2 It is a flowchart of a control method of a high-availability Redis distributed cache system according to an embodiment of the present invention;

[0046] Figure 3 It is a flowchart of another control method of a high-availability Redis distributed cache system according to an embodiment of the present invention;

[0047] Figure 4 is a schematic diagram of a processing flow of a write command request according to an embodiment of the present invention;

[0048] Figure 5 is a schematic diagram of a processing flow of a read command request according to an embodiment of the present invention;

[0049] Figure 6 It is a flowchart of another control method of a high-availability Redis distributed cache system according to an embodiment of the present invention;

[0050] Figure 7 is a schematic diagram of the process of coordinator node election according to an embodiment of the present invention;

[0051] Figure 8 It is a schematic diagram of the hardware structure of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION

[0052] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.

[0053] The Redis architecture mainly includes the following architectures:

[0054] (1) Redis master-slave deployment: Deploy a Redis architecture with one master and multiple slaves on multiple hosts. The advantages are: the slave nodes have hot backups of the master node data and can achieve read-write separation. The disadvantages are: the asynchronous replication method does not guarantee strong data consistency between the master and slaves; failure or disaster recovery requires manual intervention, and there is a risk of data loss.

[0055] (2) Redis Master-Slave Sentinel: Redis Sentinel is introduced on the basis of Redis master-slave. Sentinels are connected to each other and monitor the status of each master and slave node. When the master node fails, the sentinel elects a new master node. The advantage is that it realizes automatic recovery of master node failure. The disadvantage is that asynchronous replication still cannot guarantee strong consistency of data; when more than half of the sentinels fail or disaster occurs, the sentinels cannot be elected. If the master node fails, it will not be able to provide services normally.

[0056] (3) Redis cluster: a representative of sharded data storage, usually deploying an odd number of peer master nodes and corresponding slave nodes. Each master node is responsible for different slots. When receiving a read or write command request, it forwards it to the master node where the corresponding slot is located to perform the operation and return the result. On the other hand, when the master node goes down, the corresponding slave node is upgraded to the master node to provide services. The advantages are: sharded storage is realized, making full use of multi-machine resources; a single data is only stored in one master node and the corresponding slave node. The disadvantages are: strong data consistency is still not guaranteed between the master and slave nodes, and the slave node upgraded to the master node may lose data; when the host where the master node and the corresponding slave node are located fails or a disaster occurs, the data stored in this part is completely lost, and the cluster cannot provide services.

[0057] Therefore, the above Redis architecture has the following defects: on the one hand, the inconsistency of data between the master and slave nodes leads to data loss during fault recovery; on the other hand, when facing more serious failures and disasters, the remaining few nodes are not enough to support normal services.

[0058] To solve the above technical problems, an embodiment of the present invention provides a highly available Redis distributed cache system and a control method thereof, wherein: Figure 1As shown, the high-availability Redis distributed cache system includes: Redis master-slave sentinel module 101, coordinator and sentinel module 102 and automatic disaster recovery module 103. The Redis master-slave sentinel module 101, coordinator and sentinel module 102 and automatic disaster recovery module 103 are connected in sequence, and the coordinator and sentinel module 102 is connected to the client.

[0059] According to an embodiment of the present invention, a control method embodiment of a high-availability Redis distributed cache system is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0060] In this embodiment, a control method for a high-availability Redis distributed cache system is provided, which can be used for the above-mentioned high-availability Redis distributed cache system. Figure 2 is a flow chart of a control method of a high-availability Redis distributed cache system according to an embodiment of the present invention. Figure 2 As shown, the process includes the following steps:

[0061] Step S201, deploying Redis master nodes, Redis slave nodes and Redis sentinel nodes in the available zone of the target cache area through the Redis master-slave sentinel module; wherein one Redis master node is connected to multiple Redis slave nodes, and the Redis master node corresponds to the Redis sentinel node one by one.

[0062] Specifically, Figure 1 As shown, there are n availability zones {AZ1, AZ2, ..., AZ n}, the network and power supply between each availability zone are isolated from each other. Even if any availability zone fails or suffers a disaster, it will not affect the services of other availability zones. A Redis master-slave sentinel architecture with one master and multiple slaves is built in n availability zones. The Redis master nodes are denoted as {M1, M2, ..., M n}, a Redis master node and a Redis sentinel node are set in each availability zone, and a Redis master node is connected to multiple Redis slave nodes.

[0063] Furthermore, an automatic startup script is set for the Redis sentinel node. If the Redis sentinel node detects that the deployment port is not occupied, the instance is started.

[0064] Step S202, select a coordinator node in the Redis master node through the coordinator and sentinel modules, and use the coordinator node to perform data synchronization replication based on the read and write command requests sent by the client to obtain the read and write execution feedback results.

[0065] Specifically, in a Redis node architecture with one master and multiple slaves, data synchronization between the master and slaves adopts a state-based synchronous replication method.

[0066] Furthermore, the coordinator node is one and only one of the Redis master nodes. The coordinator node is an external service node of the highly available Redis distributed cache system, that is, the client maintains a connection with the coordinator node.

[0067] Step S203, obtaining the node status data of the Redis sentinel node during the read and write execution process through the automatic disaster recovery module, and performing disaster recovery based on the node status data of the Redis sentinel node.

[0068] Specifically, Redis sentinel nodes usually focus on monitoring the operating status of nodes. When a Redis master node fails, they can select a master and switch between the master and slave nodes through a series of mechanisms to achieve failover. Disaster recovery refers to the ability to ensure that system services continue to run uninterruptedly when a disaster occurs, and the ability to recover the system after a disaster.

[0069] Furthermore, the automatic disaster recovery module monitors the status of all nodes and automatically performs recovery in a timely manner when a failure or disaster occurs, so that the highly available Redis distributed cache system can still provide external services.

[0070] The present embodiment provides a control method for a high-availability Redis distributed cache system, which deploys Redis master nodes, Redis slave nodes and Redis sentinel nodes in an available zone. The coordinator and sentinel modules elect a coordinator node in the Redis master node, and use the coordinator node to synchronize and replicate data based on the read and write command requests sent by the client. When the Redis master node fails or is unavailable, the Redis slave node upgraded to the Redis master node will not lose data, ensuring the strong consistency of data of the available nodes. The automatic disaster recovery module performs disaster recovery based on the node status data of the Redis sentinel node, ensuring that the high-availability Redis distributed cache system provides services normally in the face of failures or disasters, avoiding the problem of data loss and business interruption caused by the failure of the Redis node, and achieving high availability and stability of the high-availability Redis distributed cache system.

[0071] In this embodiment, a control method for a high-availability Redis distributed cache system is provided, which can be used for the above-mentioned high-availability Redis distributed cache system. Figure 3 is a flow chart of a control method of a high-availability Redis distributed cache system according to an embodiment of the present invention. Figure 3 As shown, the process includes the following steps:

[0072] Step S301, deploy Redis master nodes, Redis slave nodes and Redis sentinel nodes in the available zone of the target cache area through the Redis master-slave sentinel module; wherein, one Redis master node is connected to multiple Redis slave nodes, and the Redis master node corresponds to the Redis sentinel node one by one. Figure 2 Step S201 of the illustrated embodiment will not be described in detail here.

[0073] Step S302, select a coordinator node in the Redis master node through the coordinator and sentinel modules, and use the coordinator node to perform data synchronization replication based on the read and write command requests sent by the client to obtain the read and write execution feedback results.

[0074] Specifically, the above step S302 includes:

[0075] Step S3021, obtain the preset election strategy, the coordinator and sentinel modules elect the coordinator node in the Redis master node based on the preset election strategy, and build a synchronization set based on the connection relationship between the coordinator node and the Redis master node.

[0076] Specifically, the coordinator node uses the heartbeat mechanism to establish a connection with each Redis master node, and adds all Redis master nodes that can be connected during initialization to the synchronization set. When the connection between the Redis master node and the coordinator node is disconnected, the coordinator node removes the disconnected Redis master node from the synchronization set, and the coordinator node continuously tries to connect to the disconnected Redis master node. When the connection is reestablished, the reconnected Redis master node synchronizes the data of the coordinator node and is added to the synchronization set after the incremental replication is completed.

[0077] Step S3022, the coordinator and sentinel modules send read and write command requests to the coordinator node.

[0078] Step S3023, the coordinator node sends the write command request in the read and write command request to the Redis master node and the Redis slave node for data synchronization and replication, receives the first execution feedback result after the data synchronization and replication, and sends the first execution feedback result to the client through the coordinator and sentinel module.

[0079] In some optional implementations, the above step S3023 includes:

[0080] Step a1: The coordinator node distributes the write command request to the Redis master node in the synchronization set.

[0081] Step a2, execute the write command request through the Redis master node. When the Redis master node executes successfully, the write command request is distributed to the Redis slave nodes in the data synchronization state.

[0082] Specifically, each Redis node maintains a state set, which stores a set of Redis slave nodes and Redis slave node states. The Redis slave node states include three states: "disconnected", "data syncing" and "data synchronized". When the Redis slave node cannot connect to the Redis master node, the state stored in the state set changes to "disconnected"; when the Redis slave node establishes a connection with the Redis master node, the state stored in the state set changes to "data syncing"; when the Redis slave node "synchronizing" completes data synchronization with the Redis master node, the state stored in the state set changes to "data synchronized"; among them, for the Redis slave node, the state set must be empty.

[0083] Step a3: The Redis slave node executes the write command request and sends the Redis slave node execution result to the Redis master node.

[0084] Step a4, the Redis master node receives confirmation data sent by the Redis slave node in the data synchronization state, and sends a first execution feedback result to the coordinator node based on the confirmation data.

[0085] Specifically, if the confirmation data contains all successful execution data, the Redis master node sends the first execution feedback result to the coordinator node based on the successful execution data; or, if the confirmation data contains failed execution data, the Redis master node sends a rollback command to the Redis slave node.

[0086] Furthermore, if Figure 4 As shown in the figure, when the Redis master node receives a write command request, it executes the write command request itself. If the execution fails, it returns failure. If the execution succeeds, it sends a write command request to all Redis slave nodes in the "data synchronized" state in the state set and waits. Only when all Redis slave nodes in the "data synchronized" state correctly receive the write command request and execute it successfully, they return confirmation information to the Redis master node within the timeout period. The Redis master node returns success after executing the write command request. Otherwise, the Redis master node rolls back the write command request itself, sends a rollback command to the Redis slave node, and returns failure. If each Redis master node returns success after processing the write command request, the coordinator node (i.e. Figure 4The coordinator in the process returns the write success data (i.e., the first execution feedback result) to the client; otherwise, if any Redis master node returns failure, the coordinator node initiates a rollback to the Redis master node that has executed successfully, and the coordinator node returns failure.

[0087] Step a5: The coordinator node sends the first execution feedback result to the client.

[0088] The present embodiment provides a control method for a high-availability Redis distributed cache system, in which a coordinator node performs data synchronization replication with a data-synchronized Redis master node, and a Redis master node performs data synchronization replication with a data-synchronized Redis slave node, thereby ensuring that all data-synchronized nodes in the high-availability Redis distributed cache system maintain strong data consistency with the coordinator node, retaining multiple redundant copies of consistent data, avoiding infinite blocking caused by disconnection between Redis master and slave nodes when the Redis master node replicates synchronously with all Redis slave nodes, and improving the high availability of the high-availability Redis distributed cache system.

[0089] Step S3024: The coordinator node distributes the read command request in the read and write command request to the Redis master node in the synchronization set through polling.

[0090] Step S3025, the Redis master node executes the read command request, obtains a second execution feedback result, and sends the second execution feedback result to the client through the coordinator node and the coordinator and sentinel modules in sequence.

[0091] Specifically, Figure 5 As shown, after receiving the read command request, the coordinator node sends the read command request to the Redis master node in a synchronization set in a polling load balancing manner, and the coordinator node returns the data returned by the Redis master node (ie, the second execution feedback result) to the client.

[0092] Step S303, obtain the node status data of the Redis sentinel node during the read and write execution process through the automatic disaster recovery module, and perform disaster recovery based on the node status data of the Redis sentinel node. Figure 2 Step S203 of the illustrated embodiment will not be described in detail here.

[0093] The present embodiment provides a control method for a high-availability Redis distributed cache system, which builds a synchronization set through the connection relationship between the coordinator node and the Redis master node, laying a foundation for the subsequent data synchronization and replication between the coordinator node and the Redis master node; and the coordinator node sends the write command request in the read and write command request to the Redis master node and the Redis slave node for data synchronization and replication, thereby realizing the synchronization and replication of data between the coordinator node, the Redis master node and the Redis slave node, ensuring strong data consistency and avoiding data loss; finally, in the process of processing the client read command request, the coordinator node polls all data synchronized Redis master nodes to process the read command request, so that the read command request has load balancing capability.

[0094] In this embodiment, a control method for a high-availability Redis distributed cache system is provided, which can be used for the above-mentioned high-availability Redis distributed cache system. Figure 6 is a flow chart of a control method of a high-availability Redis distributed cache system according to an embodiment of the present invention. Figure 6 As shown, the process includes the following steps:

[0095] Step S601, deploy Redis master nodes, Redis slave nodes and Redis sentinel nodes in the available zone of the target cache area through the Redis master-slave sentinel module; wherein, one Redis master node is connected to multiple Redis slave nodes, and the Redis master node corresponds to the Redis sentinel node one by one. For details, please refer to Figure 3 Step S301 of the illustrated embodiment will not be described in detail here.

[0096] Step S602, the coordinator node is selected in the Redis master node through the coordinator and sentinel modules, and based on the read and write command requests sent by the client, the coordinator node is used to perform data synchronization replication to obtain the read and write execution feedback result. Figure 3 Step S302 of the illustrated embodiment will not be described in detail here.

[0097] Step S603, obtaining the node status data of the Redis sentinel node during the read and write execution process through the automatic disaster recovery module, and performing disaster recovery based on the node status data of the Redis sentinel node.

[0098] Specifically, the above step S603 includes:

[0099] Step S6031, the automatic disaster recovery module determines the number of surviving Redis sentinel nodes according to the node status data of the Redis sentinel nodes.

[0100] Specifically, a Redis sentinel node is deployed in each availability zone. The Redis sentinel node maintains the information of the coordinator node. In addition, a synchronization set for supporting elections is maintained, which stores the Redis master node that keeps data synchronized with the coordinator node.

[0101] Furthermore, the Redis sentinel node has the function of recalculating the total number, that is, redefining the total number of sentinels according to the number of connectable sentinels, which will be used for automatic disaster recovery.

[0102] Step S6032, comparing the number of surviving Redis sentinel nodes with a preset number; wherein the preset number is half of the total number of Redis sentinel nodes.

[0103] Step S6033, if the number of surviving Redis sentinel nodes is less than the preset number, the coordinator and sentinel modules are controlled to re-elect the coordinator node, and use the re-elected coordinator node to perform data synchronization and replication.

[0104] Specifically, the Redis sentinel node is no longer any node in the election Redis slave node, but is changed to the "data synchronized" slave node in the election status set.

[0105] Furthermore, the Redis sentinel node has the function of recalculating the total number (i.e., redefining the total number of Redis sentinel nodes according to the number of connectable Redis sentinel nodes). The Redis sentinel node monitors each Redis master node {M1, M2, ..., M n} status, Redis sentinel nodes communicate with each other, such as Figure 7 As shown in the figure, when the number of monitored Redis sentinel nodes is less than half, it means that the current Redis sentinel node can no longer complete the election of the coordinator node. The automatic disaster recovery module automatically calls the recalculation function. The Redis sentinel node updates the current number of sentinel nodes and re-elects a new coordinator node, which maximizes the system availability in the event of a disaster. At the same time, the operation and maintenance personnel need to be notified to handle the physical disaster recovery. The Redis sentinel node notifies the Redis master node, and the re-selected coordinator node establishes a connection relationship with other Redis master nodes to rebuild the synchronization set.

[0106] Furthermore, if the number of surviving Redis sentinel nodes is greater than a preset number, or the number of surviving Redis sentinel nodes is zero, a monitoring alarm message is sent to the client.

[0107] Furthermore, when the number of surviving Redis sentinel nodes is monitored to decrease and exceed half, the high-availability Redis distributed cache system remains available and only warns the operation and maintenance personnel through email or text message. The operation and maintenance personnel need to manually handle the disaster and then start the downed machines in the availability zone. The Redis nodes and sentinels will automatically restart and connect. When the number of surviving Redis sentinel nodes is monitored to be zero, it means that a disaster has occurred in all availability zones, and the operation and maintenance personnel will be notified to handle it.

[0108] Furthermore, an automatic restart function is configured for each Redis node and Redis sentinel node. The Redis sentinel node ensures the automatic fault recovery capability in the partition, and its election mechanism ensures that the newly elected Redis master node must have consistent data.

[0109] The present embodiment provides a control method for a high-availability Redis distributed cache system. When the automatic disaster recovery module monitors that more than half of the Redis sentinel nodes have failed or suffered a disaster, the recalculation total number function of the Redis sentinel nodes is called, so that the remaining Redis sentinel nodes can still normally elect a new coordinator node, thereby ensuring the availability of the high-availability Redis distributed cache system and enabling the automatic disaster recovery module to have the maximum automatic disaster recovery capability. In addition, the coordinator node re-elected by the coordinator and sentinel modules belongs to the Redis master node in the synchronization set, thereby ensuring the data consistency of the new coordinator node and avoiding data loss.

[0110] In this embodiment, a highly available Redis distributed cache system is also provided, and the device is used to implement the above-mentioned embodiments and preferred implementation modes, which have been described and will not be repeated. As used below, the term "module" can implement a combination of software and / or hardware for a predetermined function. Although the device described in the following embodiments is preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.

[0111] This embodiment provides a highly available Redis distributed cache system. Figure 1 As shown, it includes: Redis master-slave sentinel module 101, coordinator and sentinel module 102 and automatic disaster recovery module 103, Redis master-slave sentinel module 101, coordinator and sentinel module 102 and automatic disaster recovery module 103 are connected in sequence, and coordinator and sentinel module 102 is connected to the client;

[0112] A Redis master-slave sentinel module 101 is used to deploy a Redis master node, a Redis slave node, and a Redis sentinel node in the available zone of the target cache area; wherein one Redis master node is connected to multiple Redis slave nodes, and the Redis master node corresponds to the Redis sentinel node one by one;

[0113] The coordinator and sentinel module 102 is used to select a coordinator node in the Redis master node, and based on the read and write command requests sent by the client, use the coordinator node to perform data synchronization replication and obtain read and write execution feedback results;

[0114] The automatic disaster recovery module 103 is used to obtain the node status data of the Redis sentinel node during the read and write execution process, and perform disaster recovery based on the node status data of the Redis sentinel node.

[0115] The further functional description of each of the above modules and units is the same as that of the above corresponding embodiments and will not be repeated here.

[0116] A high-availability Redis distributed cache system in this embodiment is presented in the form of a functional unit, where the unit refers to an ASIC (Application Specific Integrated Circuit) circuit, a processor and memory that executes one or more software or fixed programs, and / or other devices that can provide the above functions.

[0117] The embodiment of the present invention also provides a computer device having the above Figure 1 A highly available Redis distributed cache system is shown.

[0118] See also Figure 8 , Figure 8 is a schematic diagram of the structure of a computer device provided by an optional embodiment of the present invention, such as Figure 8 As shown, the computer device includes: one or more processors 10, a memory 20, and interfaces for connecting various components, including high-speed interfaces and low-speed interfaces. Various components are connected to each other using different buses for communication, and can be installed on a common mainboard or installed in other ways as needed. The processor can process instructions executed in the computer device, including instructions stored in or on the memory to display the graphical information of the GUI on an external input / output device (such as a display device coupled to the interface). In some optional embodiments, if necessary, multiple processors and / or multiple buses can be used together with multiple memories. Similarly, multiple computer devices can be connected, and each device provides some necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system). Figure 8A processor 10 is taken as an example.

[0119] The processor 10 may be a central processing unit, a network processor or a combination thereof. The processor 10 may further include a hardware chip. The hardware chip may be a dedicated integrated circuit, a programmable logic device or a combination thereof. The programmable logic device may be a complex programmable logic device, a field programmable gate array, a general purpose array logic or any combination thereof.

[0120] The memory 20 stores instructions executable by at least one processor 10, so that the at least one processor 10 executes the method shown in the above embodiment.

[0121] The memory 20 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created according to the use of the computer device, etc. In addition, the memory 20 may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some optional embodiments, the memory 20 may optionally include a memory remotely arranged relative to the processor 10, and these remote memories may be connected to the computer device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0122] The memory 20 may include a volatile memory, such as a random access memory; the memory may also include a non-volatile memory, such as a flash memory, a hard disk or a solid state drive; the memory 20 may also include a combination of the above types of memory.

[0123] The computer device also includes an input device 30 and an output device 40. The processor 10, the memory 20, the input device 30 and the output device 40 may be connected via a bus or other means. Figure 8 The example of connecting through bus is taken in the following.

[0124] The input device 30 can receive input digital or character information, and generate key signal input related to the user settings and function control of the computer device, such as a touch screen, a keypad, a mouse, a track pad, a touch pad, an indicator bar, one or more mouse buttons, a trackball, a joystick, etc. The output device 40 may include a display device, an auxiliary lighting device (e.g., an LED) and a tactile feedback device (e.g., a vibration motor), etc. The above-mentioned display device includes but is not limited to a liquid crystal display, a light emitting diode, a display and a plasma display. In some optional embodiments, the display device can be a touch screen.

[0125] The embodiment of the present invention also provides a computer-readable storage medium. The method according to the embodiment of the present invention can be implemented in hardware, firmware, or can be implemented as a computer code that can be recorded in a storage medium, or can be implemented as a computer code that is originally stored in a remote storage medium or a non-temporary machine-readable storage medium and will be stored in a local storage medium through a network download, so that the method described herein can be stored in such software processing on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only storage memory, a random access memory, a flash memory, a hard disk or a solid-state hard disk, etc.; further, the storage medium can also include a combination of the above types of memories. It can be understood that a computer, a processor, a microprocessor controller, or programmable hardware includes a storage component that can store or receive software or computer code. When the software or computer code is accessed and executed by a computer, a processor, or hardware, the method shown in the above embodiment is implemented.

[0126] A part of the present invention may be applied as a computer program product, such as a computer program instruction, which, when executed by a computer, can call or provide the method and / or technical solution according to the present invention through the operation of the computer. Those skilled in the art should understand that the existence of the computer program instruction in a computer-readable medium includes, but is not limited to, a source file, an executable file, an installation package file, etc., and accordingly, the way in which the computer program instruction is executed by the computer includes, but is not limited to: the computer directly executes the instruction, or the computer compiles the instruction and then executes the corresponding compiled program, or the computer reads and executes the instruction, or the computer reads and installs the instruction and then executes the corresponding installed program. Here, the computer-readable medium may be any available computer-readable storage medium or communication medium accessible to the computer.

[0127] Although the embodiments of the present invention have been described in conjunction with the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present invention, and such modifications and variations are all within the scope defined by the appended claims.

Claims

1. A control method for a high-availability Redis distributed cache system, characterized in that: The highly available Redis distributed cache system comprises: a Redis master-slave sentinel module, a coordinator and sentinel module and an automatic disaster recovery module, wherein the Redis master-slave sentinel module, the coordinator and sentinel module and the automatic disaster recovery module are connected in sequence, and the coordinator and sentinel module are connected to a client; the method comprises: Deploy Redis master nodes, Redis slave nodes and Redis sentinel nodes in the available zone of the target cache area through the Redis master-slave sentinel module; wherein one Redis master node is connected to multiple Redis slave nodes, and the Redis master node corresponds to the Redis sentinel node one by one; The coordinator node is selected in the Redis master node through the coordinator and sentinel modules, and based on the read and write command requests sent by the client, the coordinator node is used to perform data synchronization replication to obtain the read and write execution feedback result; The node status data of the Redis sentinel node during the read and write execution process is obtained through the automatic disaster recovery module, and disaster recovery is performed based on the node status data of the Redis sentinel node.

2. The method according to claim 1, characterized in that: The coordinator node is selected in the Redis master node through the coordinator and sentinel modules, and based on the read and write command requests sent by the client, the coordinator node is used to perform data synchronization replication to obtain the read and write execution feedback results, including: Obtain a preset election strategy, the coordinator and sentinel modules elect the coordinator node in the Redis master node based on the preset election strategy, and build a synchronization set based on the connection relationship between the coordinator node and the Redis master node; The coordinator and sentinel modules send the read and write command requests to the coordinator node; The coordinator node sends the write command request in the read-write command request to the Redis master node and the Redis slave node for data synchronization replication, receives the first execution feedback result after the data synchronization replication, and sends the first execution feedback result to the client through the coordinator and sentinel module; The coordinator node distributes the read command request in the read and write command request to the Redis master node in the synchronization set in a round-robin manner; The Redis master node executes the read command request, obtains a second execution feedback result, and sends the second execution feedback result to the client through the coordinator node and the coordinator and sentinel modules in sequence.

3. The method according to claim 2, characterized in that The coordinator node sends the write command request in the read-write command request to the Redis master node and the Redis slave node for data synchronization replication, receives a first execution feedback result after the data synchronization replication, and sends the first execution feedback result to the client through the coordinator and sentinel module, including: The coordinator node distributes the write command request to the Redis master node in the synchronization set; Execute the write command request through the Redis master node, and when the Redis master node executes successfully, distribute the write command request to the Redis slave node in the data synchronization state; The Redis slave node executes the write command request and sends the Redis slave node execution result to the Redis master node; The Redis master node receives confirmation data sent by the Redis slave node in a data synchronization state, and sends the first execution feedback result to the coordinator node based on the confirmation data; The coordinator node sends the first execution feedback result to the client.

4. The method according to claim 3, characterized in that: The Redis master node receives confirmation data sent by the Redis slave node in a data synchronization state, and sends the first execution feedback result to the coordinator node based on the confirmation data, including: If all the confirmation data are successful execution data, the Redis master node sends the first execution feedback result to the coordinator node based on the successful execution data; Alternatively, if there is execution failure data in the confirmation data, the Redis master node sends a rollback command to the Redis slave node.

5. The method according to claim 1, characterized in that Acquiring node status data of the Redis sentinel node during the read and write execution process through the automatic disaster recovery module, and performing disaster recovery based on the node status data of the Redis sentinel node, including: The automatic disaster recovery module determines the number of surviving Redis sentinel nodes according to the node status data of the Redis sentinel nodes; Compare the number of surviving Redis sentinel nodes with a preset number; wherein the preset number is half of the total number of Redis sentinel nodes; If the number of surviving Redis sentinel nodes is less than the preset number, the coordinator and sentinel modules are controlled to re-elect the coordinator node, and the re-elected coordinator node is used to perform data synchronization and replication.

6. The method according to claim 5, characterized in that Acquiring node status data of the Redis sentinel node during the read and write execution process through the automatic disaster recovery module, and performing disaster recovery based on the node status data of the Redis sentinel node, further comprising: If the number of surviving Redis sentinel nodes is greater than the preset number, or the number of surviving Redis sentinel nodes is zero, a monitoring alarm message is sent to the client.

7. A highly available Redis distributed cache system, characterized in that: The system comprises: a Redis master-slave sentinel module, a coordinator and sentinel module and an automatic disaster recovery module, wherein the Redis master-slave sentinel module, the coordinator and sentinel module and the automatic disaster recovery module are connected in sequence, and the coordinator and sentinel module are connected to a client; The Redis master-slave sentinel module is used to deploy a Redis master node, a Redis slave node and a Redis sentinel node in the available zone of the target cache area; wherein one Redis master node is connected to multiple Redis slave nodes, and the Redis master node corresponds to the Redis sentinel node one by one; The coordinator and sentinel modules are used to select a coordinator node in the Redis master node, and based on the read and write command requests sent by the client, use the coordinator node to perform data synchronization replication to obtain read and write execution feedback results; The automatic disaster recovery module is used to obtain the node status data of the Redis sentinel node during the read and write execution process, and perform disaster recovery based on the node status data of the Redis sentinel node.

8. A computer device, characterized in that: include: A memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the control method of the high-availability Redis distributed cache system according to any one of claims 1 to 6 by executing the computer instructions.

9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the control method of the high-availability Redis distributed cache system according to any one of claims 1 to 6.

10. A computer program product, characterized in that It includes computer instructions, and the computer instructions are used to enable a computer to execute the control method of the high-availability Redis distributed cache system according to any one of claims 1 to 6.

Citation Information

Cited By

  • High-availability redis distributed cache system and control method therefor

    WO2026103913A1