Redis cluster self-healing method and device, computer equipment and storage medium
By periodically monitoring the Redis cluster node status and refreshing the Slot cache on the client side, the problem of automatic reconnection of Redis clusters when the topology changes is solved, improving business continuity in the fintech and healthcare/elderly care sectors.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-02
- Publication Date
- 2026-03-13
AI Technical Summary
Existing standard Redis clients cannot automatically detect topology changes when dealing with cluster failures, leading to connection anomalies and data access failures, which particularly impacts business continuity in the fintech and healthcare/elderly care sectors.
The system monitors the status of cluster nodes by scheduling tasks on the client side, generates status monitoring results, and refreshes the Slot cache and regenerates the cluster connection topology when an anomaly occurs, thus achieving automatic reconnection.
It improves the efficiency of Redis cluster connection self-healing, avoids business interruptions caused by manual restarts, and ensures the stability of fintech and healthcare/elderly care businesses.
Smart Images

Figure CN121664628A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of Internet technology, and in particular to a Redis cluster self-healing method, apparatus, computer device and storage medium. Background Technology
[0002] With the rapid development of internet technology, distributed system architecture has become the core supporting modern enterprise-level applications. Redis, as a high-performance open-source in-memory key-value store, has been widely used in caching, session storage, and message queues due to its superior data processing speed and rich data structures. Its cluster mode achieves horizontal scaling through data sharding, significantly improving the system's concurrent processing capabilities and data capacity.
[0003] In the fintech sector, Redis clusters are a critical infrastructure supporting high-concurrency, low-latency business scenarios. For example, in core business operations such as payment transactions, real-time risk control, and user asset inquiries, Redis bears the heavy responsibility of high-speed data access. Any service interruption can lead to transaction failures, financial losses, or a degraded user experience, directly impacting a company's reputation and economic benefits.
[0004] In the fields of healthcare and elderly care, with the popularization of smart healthcare and remote health monitoring, there is a need to process large amounts of patient health data, electronic medical records, and emergency alarm signals in real time. Redis clusters are often used to cache critical medical data, manage the connection status of IoT devices, and support real-time data analysis platforms.
[0005] However, existing standard Redis clients have significant shortcomings in handling cluster failures. When a Redis cluster automatically triggers a master-slave switch due to node disk failure, network partitioning, or other reasons, or when an active-active data center switch within the same city is required for maintenance, commonly used application-layer clients typically cannot automatically detect changes in the cluster topology. The connections established after initialization and the cached slot mapping information remain unchanged, causing applications to still attempt to access the failed or degraded master node, leading to large-scale connection anomalies and data access failures. Therefore, in business areas such as fintech and healthcare / elderly care, improving the efficiency of self-healing connections in in-memory key-value storage system clusters has become a pressing technical problem to be solved. Summary of the Invention
[0006] This application provides a Redis cluster self-healing method, apparatus, computer device, and storage medium to improve the efficiency of cluster connection self-healing in a memory key-value storage system.
[0007] Firstly, this application provides a self-healing method for a Redis cluster, the method comprising: Based on the preset time interval of the scheduled tasks in the client, the status of each instance node in the current Redis cluster connected to the client is monitored, and status monitoring results are generated. If the status monitoring result indicates that the current Redis cluster is in an abnormal state, the client's Slot cache is refreshed based on the topology refresh mechanism to generate the current cluster connection topology. If the Slot cache is successfully refreshed, the client and the current Redis cluster will be reconnected through the current cluster connection topology.
[0008] Secondly, this application also provides a Redis cluster self-healing device, the device comprising: The status monitoring result generation module is used to monitor the status of each instance node in the current Redis cluster connected to the client according to the preset time interval of the scheduled task in the client, and generate status monitoring results. The current cluster connection topology generation module is used to refresh the client's Slot cache based on the topology refresh mechanism and generate the current cluster connection topology if the status monitoring result indicates that the current Redis cluster is in an abnormal state. The reconnection module is used to reconnect the client and the current Redis cluster through the current cluster connection topology if the Slot cache is successfully refreshed.
[0009] Thirdly, this application also provides a computer device, the computer device including a memory and a processor; the memory is used to store a computer program; the processor is used to execute the computer program and implement the Redis cluster self-healing method as described above when executing the computer program.
[0010] Fourthly, this application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, causes the processor to implement the Redis cluster self-healing method as described above.
[0011] This application discloses a Redis cluster self-healing method, apparatus, computer device, and storage medium. The Redis cluster self-healing method includes monitoring the status of each instance node in the currently connected Redis cluster according to a preset time interval of a scheduled task in the client, and generating a status monitoring result. If the status monitoring result indicates that the current Redis cluster is in an abnormal state, the client's Slot cache is refreshed based on a topology refresh mechanism to generate the current cluster connection topology. If the Slot cache refresh is successful, the client and the current Redis cluster are reconnected through the current cluster connection topology. Through this method, this application overcomes the static caching mechanism that relies on client-initialized topology by periodically detecting health probes, proactively discovering Redis cluster status anomalies, automatically triggering a topology refresh and reconnection mechanism, and seamlessly routing to new nodes after cluster topology changes through smooth switching of Slot cache refresh and connection. This avoids business interruptions caused by manual restarts and improves the efficiency of cluster connection self-healing in in-memory key-value storage systems in fields such as fintech and healthcare / elderly care. Attached Figure Description
[0012] To more clearly illustrate the technical solutions of the embodiments of this application, the drawings used in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0013] Figure 1 This is a schematic flowchart of a Redis cluster self-healing method provided in an embodiment of this application; Figure 2 A schematic block diagram of a Redis cluster self-healing device provided for embodiments of this application; Figure 3 A schematic block diagram of the structure of a computer device provided for an embodiment of this application. Detailed Implementation
[0014] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0015] The flowchart shown in the attached diagram is for illustrative purposes only and does not necessarily include all content and operations / steps, nor does it necessarily have to be performed in the order described. For example, some operations / steps can be broken down, combined, or partially merged, so the actual execution order may change depending on the actual situation.
[0016] It should be understood that the terminology used in this specification is for the purpose of describing particular embodiments only and is not intended to limit the scope of the application. As used in this specification and the appended claims, the singular forms “a,” “an,” and “the” are intended to include the plural forms unless the context clearly indicates otherwise.
[0017] It should also be understood that the term “and / or” as used in this application specification and the appended claims means any combination of one or more of the associated listed items and all possible combinations, and includes such combinations.
[0018] This application provides a Redis cluster self-healing method, apparatus, computer device, and storage medium. The Redis cluster self-healing method can be applied to in-memory key-value storage systems. Through periodic health checks, it overcomes the static caching mechanism that relies on client-side topology initialization, proactively detects Redis cluster anomalies, and automatically triggers topology refresh and reconnection mechanisms. Through smooth switching of slot cache refresh and connection, it seamlessly routes to new nodes after cluster topology changes, avoiding business interruptions caused by manual restarts. This improves the efficiency of in-memory key-value storage system cluster connection self-healing in fields such as fintech and healthcare / elderly care.
[0019] The following detailed description of some embodiments of this application is provided in conjunction with the accompanying drawings. Unless otherwise specified, the following embodiments and features can be combined with each other.
[0020] Please see Figure 1 , Figure 1 This is a schematic flowchart illustrating a Redis cluster self-healing method provided in an embodiment of this application. This Redis cluster self-healing method can be applied to in-memory key-value storage systems to improve the efficiency of cluster connection self-healing in such systems.
[0021] like Figure 1 As shown, the Redis cluster self-healing method specifically includes steps S10 to S30.
[0022] Step S10: Monitor the status of each instance node in the current Redis cluster connected to the client according to the preset time interval of the scheduled task in the client, and generate status monitoring results; Specifically, Redis, as a database server, provides data storage and management functions, supports various data structures such as strings, lists, and sets, and is known for its high performance and low latency; In this embodiment, the client is a Java (object-oriented programming language) application that connects to the Redis server. It provides a simple and easy-to-use API (Application Programming Interface) for operating the Redis database. As a Java client implementation, it encapsulates the Redis API, allowing developers to easily manipulate the Redis database. Its method calls are essentially the same as Redis commands. As a non-limiting example, the client could be Jedis.
[0023] When the application starts, a separate scheduled task is initialized. This task periodically performs health checks at preset time intervals (e.g., every 30 seconds). Specifically, the scheduled task sends Ping commands or executes other custom health check instructions to all Redis cluster instance nodes (including master and slave nodes) connected to the current client to monitor their activity and response status, and generates a global status monitoring result by combining the check results of each node. If any abnormal situation is detected, such as the master node being unreachable or more than half of the nodes being unresponsive, the current Redis cluster is determined to be in an abnormal state.
[0024] In the fintech business field (such as real-time transaction processing systems or internet order issuance systems), through pre-set timed tasks in the client, multi-dimensional status monitoring is performed on each instance node in the current Redis cluster at time intervals (such as every 30 seconds) set according to the financial-grade business continuity requirements. Ping commands are sent to each node and key response parameters are collected, including response status, response time, and node load indicators. When a node is detected to have not returned a Ping response, or the response time exceeds the strict threshold preset in the financial transaction scenario (such as 50 milliseconds), or the node memory usage exceeds the warning line, financial business status monitoring results containing abnormal node identifiers and abnormal types are generated.
[0025] When the healthcare application service starts, initialize a highly reliable scheduled task. Healthcare services have higher requirements for data stability and continuity than for extreme latency. The preset time interval can be set to a relatively lenient but reliable period (such as once every 30 seconds) to avoid putting unnecessary pressure on the Redis cluster that carries a large number of medical IoT device connections and historical medical record data due to excessively frequent checks.
[0026] During each detection cycle, the client sends a Ping command to each instance node in the current Redis cluster. Nodes carrying critical data (such as the master node storing real-time vital signs of emergency patients and the slave nodes storing cached copies of medical records) are prioritized for inspection. A response timeout threshold (e.g., 2 seconds) is set to balance reliability and sensitivity.
[0027] The response status of each instance node is collected and recorded. Key parameters include whether a Pong response was received (result parameter) and the specific response time (response time parameter). For healthcare operations, special attention needs to be paid to abnormal fluctuations in consecutive short-term responses. Status monitoring results are generated based on the fault tolerance rules of the healthcare operations. The rules are as follows: If the core master node storing active patient sessions or real-time alarm information becomes unreachable, or if any node times out multiple times consecutively, it is immediately determined to be in an "abnormal state," and a high-priority alarm is triggered to quickly initiate the self-healing process and prevent impact on the diagnostic operations of medical staff or emergency call responses for elderly patients. If all nodes respond normally and the latency is within the threshold, it is determined to be in a "normal state," ensuring the continuous stability of healthcare data services.
[0028] Step S20: If the status monitoring result indicates that the current Redis cluster is in an abnormal state, then refresh the client's Slot cache based on the topology refresh mechanism to generate the current cluster connection topology. Specifically, when it is confirmed that the current Redis cluster is in an abnormal state, a topology refresh mechanism is triggered. The client initiates a cluster topology query request from its locally cached known available nodes (e.g., a slave node that was initially successfully connected or a stable configuration node) to re-obtain the latest mapping relationship between slots and instance nodes for the entire cluster. The client uses this latest mapping relationship to completely refresh its local slot cache, overwriting outdated mapping information due to master-slave switching or dual-active switching, and generating a current cluster connection topology map that accurately reflects the current cluster architecture.
[0029] Step S30: If the Slot cache is successfully refreshed, reconnect the client and the current Redis cluster using the current cluster connection topology.
[0030] Specifically, Slot is the core mechanism for data sharding in a Redis cluster, distributing key-value pairs evenly across nodes, known as slots. Once the Slot cache is successfully updated, all subsequent data access requests initiated by that client will no longer be routed based on the old, invalid topology. Instead, they will strictly adhere to the newly generated current cluster connection topology, automatically addressing the new master node or a dual-active cluster instance that has switched to an active state. This process automatically completes the reconnection and session recovery between the client and the healthy cluster without manual intervention, enabling the application system to quickly heal from failures and restore normal data access capabilities.
[0031] For example, during the application startup phase, the client loads the initialization configuration and instantiates the scheduled task. The scheduled task periodically obtains the list of all instance nodes in the current Redis cluster at a preset time interval (10 seconds by default, which can be dynamically adjusted through the configuration center). It executes the Ping command on each node in turn and records the response time. If no valid Ping response is received within three consecutive detection cycles or the response time exceeds the 200-millisecond threshold, the node is determined to be in an abnormal state and the cluster abnormal score is accumulated. When the number of abnormal nodes exceeds 50% of the total number of nodes in the cluster or the original master node is marked as abnormal, a status monitoring result representing the current Redis cluster in an abnormal state is generated and the topology refresh process is triggered.
[0032] The client selects the most recently successfully connected available node from the local cache, sends a slot allocation query command to the cluster through that node, obtains real-time slot allocation data, parses the returned nested array structure, extracts the master node IP address, port number, and node ID corresponding to each slot range, and synchronously obtains slave node information. The parsed slot-node mapping relationship is compared with the local Slot cache to identify the changed slot ranges. For slots where the master node has changed, the old client connection pool corresponding to the slot is immediately closed and a new connection pool object is created based on the new master address. At the same time, the slave node routing information is updated, and finally, the current cluster connection topology containing the latest correspondence between all slots and each node in the current cluster is generated.
[0033] After the Slot cache is successfully refreshed, the client iterates through the slot and node mapping relationships in the current cluster connection topology. For each slot interval, it checks whether there is a valid connection in the connection pool of the corresponding master node. If there is no valid connection or the existing connection has been marked as invalid, a new connection pool instance is created based on the latest IP address and port number of the master node. At the same time, the connection pool routing information of the corresponding slave nodes of each master node is updated synchronously. After the connection is rebuilt, at least one verification Ping command is sent to the cluster. If a Pong response is received, the connection is considered successful. Finally, the client's request is routed to the newly established connection pool, and all abandoned old connections are closed to release resources, realizing the complete reconnection and self-healing recovery of the client with the current Redis cluster.
[0034] This embodiment discloses a Redis cluster self-healing method, apparatus, computer device, and storage medium. The Redis cluster self-healing method includes monitoring the status of each instance node in the currently connected Redis cluster according to a preset time interval of a scheduled task in the client, and generating a status monitoring result. If the status monitoring result indicates that the current Redis cluster is in an abnormal state, the client's Slot cache is refreshed based on a topology refresh mechanism to generate the current cluster connection topology. If the Slot cache refresh is successful, the client and the current Redis cluster are reconnected through the current cluster connection topology. Through this method, this application overcomes the static caching mechanism that relies on client-initialized topology by periodically detecting health probes, proactively discovering Redis cluster status anomalies, automatically triggering a topology refresh and reconnection mechanism, and seamlessly routing to new nodes after cluster topology changes through smooth switching of Slot cache refresh and connection. This avoids business interruption caused by manual restarts, improving the efficiency of cluster connection self-healing in fintech, healthcare, and elderly care sectors.
[0035] based on Figure 1 In the illustrated embodiment, step S10 includes: The client sends Ping commands to each instance node in the current Redis cluster according to the preset time interval. Collect the response parameters of the Pong response received by the client, wherein the Pong response is the response instruction generated by each instance node according to the Ping command; The status monitoring results are generated based on the response parameters.
[0036] Specifically, after the client's built-in scheduled task is triggered, it iterates through all instance nodes in the current Redis cluster topology at preset time intervals, sending a Ping command in Redis protocol format to each node sequentially through the established connection channel. Upon receiving the Ping command, each instance node, under normal service conditions, immediately returns a Pong response. The client collects the parameters of this response, including whether a Pong response was received, the response time, and the node from which the response originated. If no Pong response is received within a certain detection period or the response time exceeds a preset threshold, the node is marked as potentially abnormal, and the number of consecutive failures is recorded. If no valid Pong response is received for three consecutive detection periods, or the response time consistently exceeds the threshold, the current Redis cluster is determined to be in an abnormal state.
[0037] In a specific embodiment, generating the status monitoring result based on the response parameters includes: If the response result parameter indicates that the instance node has not generated the Pong response, or the response time parameter exceeds the preset response time threshold, then the status monitoring result is determined to be that the current Redis cluster belongs to the abnormal state. If the response result parameter is the Pong response generated by the instance node and the response time parameter is less than or equal to the preset response time threshold, then the status monitoring result is determined to be that the current Redis cluster is in a normal state.
[0038] Specifically, when the health monitoring process is triggered, a Ping command is sent to each instance node in the current Redis cluster in sequence, and a response waiting timer is started. If no Ping response is received after the preset response time threshold, or if abnormal response parameters such as network connection timeout or connection reset are clearly received, the node is determined to be in an abnormal state, and the overall cluster status is marked as abnormal, generating a status monitoring result containing information such as node disconnection and response timeout. If a Ping response is successfully received within the threshold time and the response time parameter is less than or equal to the preset response time threshold, the current Redis cluster is determined to be in a normal state. When more than half of the master nodes in the cluster return normal responses, a status monitoring result indicating that the current Redis cluster is in a normal state is generated.
[0039] based on Figure 1 In the illustrated embodiment, the steps preceding step S10 include: When the client starts, the configuration information of the current Redis cluster is initialized; The connection between the client and the current Redis cluster is established using the configuration information.
[0040] Specifically, during the client startup initialization phase, pre-defined configuration information is loaded, including the domain name and port mappings of each instance node in the Redis cluster, connection pool parameters (such as maximum number of connections and timeout), authentication password, and cluster mode identifier. Based on this configuration information, a Redis cluster object is instantiated, the initial node address is obtained through domain name resolution, and a persistent connection is established. Simultaneously, the first Slot topology retrieval is triggered, and the mapping relationship between each cluster Slot and its corresponding node is cached in local memory, completing the initial connection construction between the client and the current Redis cluster.
[0041] In a specific embodiment, before step S30, the following is included: In the event that the Slot cache refresh fails, the Slot cache is initialized using the configuration information of the current Redis cluster to generate active-active cluster instance information. The connection between the client and the current Redis cluster is re-established using the dual-active cluster instance information.
[0042] Specifically, when a Slot cache refresh failure is detected, the system automatically rolls back to the initialization phase. It reloads the initial configuration information of the current Redis cluster to perform initialization processing on the Slot cache, thereby obtaining and generating active-active cluster instance information, including the local disaster recovery node. Based on this active-active cluster instance information, a valid connection is re-established between the client and the current Redis cluster, completing connection recovery in the active-active failover scenario. The client reads the current Redis cluster configuration information initialized at startup. The client obtains the new addresses and ports of each instance node in the dual-active cluster by re-resolving these domain names, forces the local Slot cache to be initialized to the topology of the dual-active cluster, generates dual-active cluster instance information containing the new master-slave relationship, and finally rebuilds the connection pool based on this information to complete the cross-data center traffic switch from the master cluster to the dual-active cluster, achieving final self-healing in the dual-active switch scenario.
[0043] based on Figure 1 In the illustrated embodiment, step S20 includes: The topology refresh mechanism is used to determine the currently healthy nodes in the current Redis cluster. The client sends a query request to the currently normal node to determine the mapping relationship between the cluster slots and each instance node in the current Redis cluster; The Slot cache is refreshed according to the mapping relationship to generate the current cluster connection topology.
[0044] Specifically, a topology refresh mechanism identifies and determines all live, healthy nodes in the current Redis cluster. Clients then send slot allocation query requests to these healthy nodes to obtain the complete mapping between slots and instance nodes in the current cluster. Based on the latest mapping, the local slot cache is dynamically refreshed to generate an accurate current cluster connection topology.
[0045] Based on any of the above embodiments, in this embodiment, step S30 is followed by: Update the routing information between the client and the current Redis cluster based on the current cluster connection topology; Based on the routing information, the client sends verification commands to each instance node in the current Redis cluster. If the client receives a response instruction corresponding to each of the verification instructions within a preset time period, it is determined that the client and the current Redis cluster have successfully reconnected.
[0046] Specifically, the routing information between the client and the Redis cluster is dynamically updated based on the current cluster connection topology. Based on the updated routing information, the client sends verification commands to each instance node in the cluster to verify connectivity.
[0047] If the client successfully receives all corresponding verification commands within the preset time period, it confirms that the client has successfully reconnected to the Redis cluster, completing the final verification of the self-healing process.
[0048] Please see Figure 2 , Figure 2 This application provides a schematic block diagram of a Redis cluster self-healing device, which is used to execute the aforementioned Redis cluster self-healing method. The Redis cluster self-healing device can be configured on a server.
[0049] like Figure 2 As shown, the Redis cluster self-healing device 400 includes: The status monitoring result generation module 410 is used to monitor the status of each instance node in the current Redis cluster connected to the client according to the preset time interval of the scheduled task in the client, and generate status monitoring results. The current cluster connection topology generation module 420 is used to refresh the client's Slot cache based on the topology refresh mechanism and generate the current cluster connection topology if the status monitoring result indicates that the current Redis cluster is in an abnormal state. The reconnection module 430 is used to reconnect the client and the current Redis cluster through the current cluster connection topology if the Slot cache is successfully refreshed.
[0050] Furthermore, the status monitoring result generation module 410 includes: Ping command generation unit, used by the client to send Ping commands to each instance node in the current Redis cluster according to the preset time interval; The response parameter acquisition unit is used to acquire the response parameters of the client receiving the Pong response, wherein the Pong response is the response instruction generated by each instance node according to the Ping command; A status monitoring result generation unit is used to generate the status monitoring result based on the response parameters.
[0051] Furthermore, the status monitoring result generation unit includes: An abnormal state determination subunit is used to determine that the current Redis cluster belongs to the abnormal state if the response result parameter is that the instance node has not generated the Pong response, or the response time parameter exceeds a preset response time threshold. The normal state determination subunit is used to determine that the current Redis cluster is in a normal state if the response result parameter is the Pong response generated by the instance node and the response time parameter is less than or equal to the preset response time threshold.
[0052] Furthermore, the Redis cluster self-healing device 400 includes: The configuration information initialization module is used to initialize the configuration information of the current Redis cluster when the client starts. A connection establishment module is used to establish a connection between the client and the current Redis cluster using the configuration information.
[0053] Furthermore, the Redis cluster self-healing device 400 includes: The active-active cluster instance information generation module is used to initialize the Slot cache using the configuration information of the current Redis cluster and generate active-active cluster instance information in the event that the Slot cache refresh fails. The reconnection module is used to re-establish the connection between the client and the current Redis cluster using the dual-active cluster instance information.
[0054] Furthermore, the current cluster connection topology generation module 420 includes: The current normal node determination unit is used to determine the current normal node in the current Redis cluster through the topology refresh mechanism; The mapping relationship determination unit is used to send a query request to the currently normal node through the client to determine the mapping relationship between the cluster slots and each instance node in the current Redis cluster; The current cluster connection topology generation unit is used to refresh the Slot cache according to the mapping relationship and generate the current cluster connection topology.
[0055] Furthermore, the Redis cluster self-healing device 400 includes: The routing information update module is used to update the routing information between the client and the current Redis cluster according to the current cluster connection topology; A verification instruction sending module is used to send verification instructions to each instance node in the current Redis cluster through the client based on the routing information; The reconnection success verification module is used to determine that the client and the current Redis cluster have successfully reconnected if the client receives a response instruction corresponding to each of the verification instructions within a preset time period.
[0056] It should be noted that those skilled in the art will understand that, for the sake of convenience and brevity, the specific working processes of the above-described apparatus and modules can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0057] The aforementioned device can be implemented as a computer program, which can be used in, for example... Figure 3 It runs on the computer device shown.
[0058] Please see Figure 3 , Figure 3 This is a schematic block diagram illustrating the structure of a computer device according to an embodiment of this application. The computer device may be a server.
[0059] See Figure 3 The computer device includes a processor, memory, and network interface connected via a system bus, wherein the memory may include non-volatile storage media and internal memory.
[0060] Non-volatile storage media can store operating systems and computer programs. These computer programs include program instructions that, when executed, cause the processor to perform any Redis cluster self-healing method.
[0061] The processor provides computing and control capabilities, supporting the operation of the entire computer device.
[0062] Internal memory provides an environment for the execution of computer programs in non-volatile storage media, which, when executed by a processor, enable the processor to perform any Redis cluster self-healing method.
[0063] This network interface is used for network communication, such as sending assigned tasks. Those skilled in the art will understand that... Figure 3 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0064] It should be understood that the processor can be a Central Processing Unit (CPU), but it can also be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. Among these, a general-purpose processor can be a microprocessor or any conventional processor.
[0065] In one embodiment, the processor is configured to run a computer program stored in memory to perform the following steps: Based on the preset time interval of the scheduled tasks in the client, the status of each instance node in the current Redis cluster connected to the client is monitored, and status monitoring results are generated. If the status monitoring result indicates that the current Redis cluster is in an abnormal state, the client's Slot cache is refreshed based on the topology refresh mechanism to generate the current cluster connection topology. If the Slot cache is successfully refreshed, the client and the current Redis cluster will be reconnected through the current cluster connection topology.
[0066] In one embodiment, the status of each instance node in the current Redis cluster connected to the client is monitored according to a preset time interval of the scheduled task in the client, and status monitoring results are generated to achieve the following: The client sends Ping commands to each instance node in the current Redis cluster according to the preset time interval. Collect the response parameters of the Pong response received by the client, wherein the Pong response is the response instruction generated by each instance node according to the Ping command; The status monitoring results are generated based on the response parameters.
[0067] In one embodiment, the status monitoring result is generated based on the response parameters to achieve: If the response result parameter indicates that the instance node has not generated the Pong response, or the response time parameter exceeds the preset response time threshold, then the status monitoring result is determined to be that the current Redis cluster belongs to the abnormal state. If the response result parameter is the Pong response generated by the instance node and the response time parameter is less than or equal to the preset response time threshold, then the status monitoring result is determined to be that the current Redis cluster is in a normal state.
[0068] In one embodiment, before generating the status monitoring results, the status of each instance node in the current Redis cluster connected to the client is monitored according to a preset time interval of the scheduled task in the client, and the following is implemented: When the client starts, the configuration information of the current Redis cluster is initialized; The connection between the client and the current Redis cluster is established using the configuration information.
[0069] In one embodiment, before reconnecting the client and the current Redis cluster via the current cluster connection topology after the Slot cache refresh is successful, the following is implemented: In the event that the Slot cache refresh fails, the Slot cache is initialized using the configuration information of the current Redis cluster to generate active-active cluster instance information. The connection between the client and the current Redis cluster is re-established using the dual-active cluster instance information.
[0070] In one embodiment, if the status monitoring result indicates that the current Redis cluster is in an abnormal state, the client's Slot cache is refreshed based on the topology refresh mechanism to generate the current cluster connection topology, for the purpose of: The topology refresh mechanism is used to determine the currently healthy nodes in the current Redis cluster. The client sends a query request to the currently normal node to determine the mapping relationship between the cluster slots and each instance node in the current Redis cluster; The Slot cache is refreshed according to the mapping relationship to generate the current cluster connection topology.
[0071] In one embodiment, after the Slot cache refresh is successful, reconnecting the client and the current Redis cluster via the current cluster connection topology is used to achieve the following: Update the routing information between the client and the current Redis cluster based on the current cluster connection topology; Based on the routing information, the client sends verification commands to each instance node in the current Redis cluster. If the client receives a response instruction corresponding to each of the verification instructions within a preset time period, it is determined that the client and the current Redis cluster have successfully reconnected.
[0072] The embodiments of this application also provide a computer-readable storage medium storing a computer program, the computer program including program instructions, and the processor executing the program instructions to implement any of the Redis cluster self-healing methods provided in the embodiments of this application.
[0073] The computer-readable storage medium may be an internal storage unit of the computer device described in the foregoing embodiments, such as the hard disk or memory of the computer device. The computer-readable storage medium may also be an external storage device of the computer device, such as a plug-in hard disk, SmartMedia Card (SMC), Secure Digital (SD) card, or Flash Card equipped on the computer device.
[0074] The user personal information involved in this application embodiment is all authorized (with knowledge and consent) by the relevant parties or fully authorized by all parties, and the executing entity can obtain it through various legal and compliant means. The collection, storage, use, processing, transmission, provision, and disclosure of the information, data, and signals involved all comply with the relevant laws and regulations of the relevant countries and regions, and do not violate public order and good morals. It should be noted that if any software tools or components not belonging to this company appear in this application embodiment, they are merely illustrative examples and do not represent actual use.
[0075] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in this application, and these modifications or substitutions should all be covered within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A self-healing method for a Redis cluster, characterized in that, include: Based on the preset time interval of the scheduled tasks in the client, the status of each instance node in the current Redis cluster connected to the client is monitored, and status monitoring results are generated. If the status monitoring result indicates that the current Redis cluster is in an abnormal state, the client's Slot cache is refreshed based on the topology refresh mechanism to generate the current cluster connection topology. If the Slot cache is successfully refreshed, the client and the current Redis cluster will be reconnected through the current cluster connection topology.
2. The Redis cluster self-healing method according to claim 1, characterized in that, The step of monitoring the status of each instance node in the current Redis cluster connected to the client according to the preset time interval of the scheduled task in the client, and generating status monitoring results, includes: The client sends Ping commands to each instance node in the current Redis cluster according to the preset time interval. Collect the response parameters of the Pong response received by the client, wherein the Pong response is the response instruction generated by each instance node according to the Ping command; The status monitoring results are generated based on the response parameters.
3. The Redis cluster self-healing method according to claim 2, characterized in that, The response parameters include response result parameters and response time parameters. Generating the status monitoring result based on the response parameters includes: If the response result parameter indicates that the instance node has not generated the Pong response, or the response time parameter exceeds the preset response time threshold, then the status monitoring result is determined to be that the current Redis cluster belongs to the abnormal state. If the response result parameter is the Pong response generated by the instance node and the response time parameter is less than or equal to the preset response time threshold, then the status monitoring result is determined to be that the current Redis cluster is in a normal state.
4. The Redis cluster self-healing method according to claim 1, characterized in that, Before generating the status monitoring results by monitoring the status of each instance node in the current Redis cluster connected to the client according to the preset time interval of the scheduled task in the client, the process includes: When the client starts, the configuration information of the current Redis cluster is initialized; The connection between the client and the current Redis cluster is established using the configuration information.
5. The Redis cluster self-healing method according to claim 4, characterized in that, Before reconnecting the client and the current Redis cluster via the current cluster connection topology after the Slot cache refresh is successful, the process includes: In the event that the Slot cache refresh fails, the Slot cache is initialized using the configuration information of the current Redis cluster to generate active-active cluster instance information. The connection between the client and the current Redis cluster is re-established using the dual-active cluster instance information.
6. The Redis cluster self-healing method according to claim 1, characterized in that, If the status monitoring result indicates that the current Redis cluster is in an abnormal state, then the client's Slot cache is refreshed based on the topology refresh mechanism to generate the current cluster connection topology, including: The topology refresh mechanism is used to determine the currently healthy nodes in the current Redis cluster. The client sends a query request to the currently normal node to determine the mapping relationship between the cluster slots and each instance node in the current Redis cluster; The Slot cache is refreshed according to the mapping relationship to generate the current cluster connection topology.
7. The Redis cluster self-healing method according to any one of claims 1 to 6, characterized in that, After the Slot cache is successfully refreshed, and the client and the current Redis cluster are reconnected via the current cluster connection topology, the following steps are included: Update the routing information between the client and the current Redis cluster based on the current cluster connection topology; Based on the routing information, the client sends verification commands to each instance node in the current Redis cluster. If the client receives a response instruction corresponding to each of the verification instructions within a preset time period, it is determined that the client and the current Redis cluster have successfully reconnected.
8. A Redis cluster self-healing device, characterized in that, include: The status monitoring result generation module is used to monitor the status of each instance node in the current Redis cluster connected to the client according to the preset time interval of the scheduled task in the client, and generate status monitoring results. The current cluster connection topology generation module is used to refresh the client's Slot cache based on the topology refresh mechanism and generate the current cluster connection topology if the status monitoring result indicates that the current Redis cluster is in an abnormal state. The reconnection module is used to reconnect the client and the current Redis cluster through the current cluster connection topology if the Slot cache is successfully refreshed.
9. A computer device, characterized in that, The computer device includes a memory and a processor; The memory is used to store computer programs; The processor is configured to execute the computer program and, in executing the computer program, implement the Redis cluster self-healing method as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, causes the processor to implement the Redis cluster self-healing method as described in any one of claims 1 to 7.