Redis-based message processing method and device, equipment and storage medium

By implementing a delay queue on Redis and using polling methods to process messages, the problem of low reliability of existing delay queues is solved, and efficient and reliable message processing is achieved, suitable for large data volume and multi-cluster scenarios.

CN119668794APending Publication Date: 2025-03-21CHINA MERCHANTS BANK
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202411532208.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-30
Publication Date
2025-03-21

AI Technical Summary

Technical Problem

The existing delay queues have low reliability and are difficult to effectively handle large data scenarios and multi-cluster modes.

Method used

By implementing a delay queue based on Redis, the preset polling method is used to poll the delay queue configured by Redis, determine the target polling result, and message processing is performed based on the results.

Benefits of technology

It improves the reliability of latency queues and the utilization of system resources. It is independent of external systems, supports scale-out and multi-cluster mode, and is suitable for large data volume scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119668794A_ABST
    Figure CN119668794A_ABST
Patent Text Reader

Abstract

The invention discloses a Redis-based message processing method and device, equipment and a storage medium, and relates to the technical field of delay queues, and the Redis-based message processing method comprises the steps: issuing a delay message to a delay queue; polling the delay queue configured by the Redis according to a preset polling method, and determining a target polling result; and performing message processing according to the target polling result. The delay queue is realized based on Redis, consumption and dependence on system resources can be effectively reduced, the function is realized independent of an external system, a multi-cluster mode can be realized through transverse expansion, and the method is suitable for a large-data-volume scene, so that orderliness of data, message uniqueness and reliability are ensured, and the method is suitable for large-data-volume scenes. And the method can be applied to specific business scenes such as order timeout processing, timed task scheduling, risk control auditing, reservation service and the like, and is realized from the aspects of timing and time delay.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of delay queues, and in particular to a message processing method, apparatus, device and storage medium based on Redis. Background Art

[0002] A delay queue is a queue with a delayed consumption function. You can specify messages in the queue so that they are consumed or retried after a delay. Although scheduled tasks can also achieve similar functions to a certain extent, when this function needs to be abstracted and applied to more business and technical scenarios, a more general solution such as a delay queue is needed to implement it. In addition, delay queues also have richer functions, such as ensuring that business message data is not lost, troubleshooting log message records, and message monitoring management. With the continuous update and iteration of technology and the continuous changes in business scenarios, there are more and more ways to implement delay queues, and they are more and more frequently used in various systems. Delay queues make the system more available and stable. There are many existing delay queue implementation solutions, which can be implemented through the Concurrent package of JDK (Java Development Kit) or Quartz (Quartz scheduling framework) timer task, or through the time wheel algorithm of Kafka (a distributed stream processing platform, often used to build real-time data pipelines and stream applications), Netty (a high-performance asynchronous event-driven network application framework for rapid development of maintainable high-performance protocol servers and clients), Zookeeper (a distributed coordination service for maintaining configuration information, naming, providing distributed synchronization and providing group services), and the delayed delivery function of message queues such as RocketMq (a distributed message middleware that supports high-availability and high-performance message delivery), RabbitMQ (an open source message broker and queue server that supports multiple message protocols), and Pulsar (a distributed message and stream platform that supports multi-tenancy and cross-regional replication). However, how to solve the low reliability of existing delay queues has become an urgent problem to be solved. Summary of the invention

[0003] The main purpose of this application is to provide a Redis-based message processing method, device, equipment and storage medium, aiming to solve the technical problem of low reliability of data processing in existing delay queues.

[0004] To achieve the above purpose, the present application proposes a message processing method based on Redis, and the message processing method based on Redis includes: Publish delayed messages to the delay queue; Poll the delay queue configured by Redis according to the preset polling method to determine the target polling result; Message processing is performed according to the target polling result.

[0005] In one embodiment, the step of polling the delay queue configured by Redis according to a preset polling method to determine the target polling result includes: Poll the delay queue configured in Redis according to the preset polling method to obtain the delay message; Determine a corresponding message execution time according to the delayed message; The target polling result is determined according to the current polling time and the message execution time.

[0006] In one embodiment, determining the target polling result according to the current polling time and the message execution time includes: Compare the current polling time with the message execution time to obtain a time comparison result; When the time comparison result is that the message execution time is less than the current polling time, determining that the target polling result is a message failure result; When the time comparison result is that the message execution time is greater than or equal to the current polling time, it is determined that the target polling result is the message execution result.

[0007] In one embodiment, the step of performing message processing according to the target polling result includes: When the target polling result is a message execution result, parsing the delayed message corresponding to the message execution result to obtain target processing data; The target processing data is processed to complete message processing.

[0008] In one embodiment, before the step of publishing the delayed message to the delay queue, the method further includes: Perform initialization processing according to the configuration information and determine the initialization state; When the initialization state is an initialization completion state, determining a load balancing state according to a current data volume and a data volume threshold; When the load balancing state is a load balancing completion state, a step of publishing a delay message to a delay queue is performed.

[0009] In one embodiment, when the initialization state is the initialization completion state, the step of determining the load balancing state according to the current data volume and the data volume threshold comprises: When the initialization state is an initialization completion state, comparing the current data volume with a data volume threshold; When the current data volume is greater than or equal to the data volume threshold, load balancing processing is performed according to a hash algorithm to determine a load balancing state.

[0010] In one embodiment, after the step of performing message processing according to the target polling result, the method further includes: Get consumption delay time, consumption rate and number of tasks processed; Analyze the consumption delay time, the consumption rate, and the number of task processing to obtain a consumption analysis result; Generate corresponding target optimization suggestion information according to the consumption analysis result; The configuration information is optimized according to the target optimization suggestion information to obtain optimized configuration information.

[0011] In addition, to achieve the above purpose, the present application also proposes a message processing device based on Redis, and the message processing device based on Redis includes: A publishing module is used to publish delayed messages to a delay queue; The polling module is used to poll the delay queue configured by Redis according to the preset polling method to determine the target polling result; A processing module is used to process messages according to the target polling result.

[0012] In addition, to achieve the above-mentioned purpose, the present application also proposes a Redis-based message processing device, the device comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, the computer program being configured to implement the steps of the Redis-based message processing method as described above.

[0013] In addition, to achieve the above-mentioned purpose, the present application also proposes a storage medium, which is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by the processor, the steps of the Redis-based message processing method described above are implemented.

[0014] In addition, to achieve the above-mentioned purpose, the present application also provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, the steps of the Redis-based message processing method described above are implemented.

[0015] This application publishes delayed messages to the delay queue; polls the delay queue configured by Redis according to the preset polling method to determine the target polling result; and processes the message according to the target polling result. By implementing the delay queue based on Redis, the consumption and dependence on system resources can be effectively reduced, and the function can be implemented independently of the external system, and it can be horizontally expanded to realize multi-cluster mode, which is suitable for large data volume scenarios, thereby ensuring the orderliness of data, uniqueness of messages, and reliability. It can also be applied to specific business scenarios such as order timeout processing, scheduled task scheduling, risk control review, and appointment services, and can be implemented from the aspects of timing and time delay. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0017] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0018] Figure 1 A flowchart of the message processing method based on Redis provided in the present application; Figure 2 The overall framework diagram provided for the first embodiment of the message processing method based on Redis of this application; Figure 3 A flowchart of the second embodiment of the message processing method based on Redis provided in this application; Figure 4 A schematic diagram of a load balancing process provided for Embodiment 2 of the message processing method based on Redis of this application; Figure 5 A brief flowchart of a message processing method based on Redis provided in Example 1 of the present application; Figure 6 This is a schematic diagram of the module structure of a message processing device based on Redis in an embodiment of the present application; Figure 7 This is a schematic diagram of the device structure of the hardware operating environment involved in the Redis-based message processing method in an embodiment of the present application.

[0019] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION

[0020] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not used to limit the present application.

[0021] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.

[0022] The main solution of the embodiment of the present application is: publish delayed messages to the delay queue; poll the delay queue configured by Redis according to a preset polling method to determine the target polling result; and process the message according to the target polling result.

[0023] A delay queue is a queue with a delayed consumption function. You can specify messages in the queue so that they are consumed or retried after a delay. Although scheduled tasks can also achieve similar functions to a certain extent, when this function needs to be abstracted and applied to more business and technical scenarios, a more general solution such as a delay queue is needed to implement it. In addition, delay queues also have richer functions, such as ensuring that business message data is not lost, troubleshooting log message records, and message monitoring management. With the continuous update and iteration of technology and the continuous changes in business scenarios, there are more and more ways to implement delay queues, and they are more and more frequently used in various systems. Delay queues make the system more available and stable. There are many existing delay queue implementation solutions, which can be implemented through the Concurrent package of JDK (Java Development Kit) or Quartz (Quartz scheduling framework) timer task, or through the time wheel algorithm of Kafka (a distributed stream processing platform, often used to build real-time data pipelines and stream applications), Netty (a high-performance asynchronous event-driven network application framework for rapid development of maintainable high-performance protocol servers and clients), Zookeeper (a distributed coordination service for maintaining configuration information, naming, providing distributed synchronization and providing group services), and the delayed delivery function of message queues such as RocketMq (a distributed message middleware that supports high-availability and high-performance message delivery), RabbitMQ (an open source message broker and queue server that supports multiple message protocols), and Pulsar (a distributed message and stream platform that supports multi-tenancy and cross-regional replication). However, how to solve the low reliability of existing delay queues has become an urgent problem to be solved.

[0024] This application publishes delayed messages to the delay queue; polls the delay queue configured by Redis according to the preset polling method to determine the target polling result; and processes the message according to the target polling result. By implementing the delay queue based on Redis, the consumption and dependence on system resources can be effectively reduced, and the function can be implemented independently of the external system, and it can be horizontally expanded to realize multi-cluster mode, which is suitable for large data volume scenarios, thereby ensuring the orderliness of data, uniqueness of messages, and reliability. It can also be applied to specific business scenarios such as order timeout processing, scheduled task scheduling, risk control review, and appointment services, and can be implemented from the aspects of timing and time delay.

[0025] It should be noted that the execution subject of this embodiment can be a computing service device with data processing, network communication and program running functions, such as a tablet computer, a personal computer, a mobile phone, etc., or a Redis-based message processing device that can realize the above functions. The following takes the Redis-based message processing device as the execution subject as an example to illustrate this embodiment and the following embodiments.

[0026] Based on this, the embodiment of the present application provides a message processing method based on Redis, referring to Figure 1 , Figure 1 This is a flow chart of the first embodiment of the message processing method based on Redis of the present application.

[0027] In this embodiment, the Redis-based message processing method includes steps S10 to S30: Step S10, publishing a delay message to a delay queue; It should be noted that if Figure 2 As shown, the independent delay queue based on Redis configuration in this embodiment is composed of a delay queue module and a configuration module, wherein the delay queue module: this module is the core implementation part of the Redis zset delay queue, the production and consumption of messages in the delay queue and the extended load balancing function are all built in this module, and a unified interface is provided for external systems to use; configuration module: this module is some initial configuration related to the Redis client. This part is separated independently and provides a set of default configurations, which can be used directly by external systems, or changed according to actual needs.

[0028] It can be understood that delayed messages refer to messages for delayed consumption generated by producers based on user needs, and delayed queues refer to a special message queue used to process tasks that need to be processed at a certain point in the future.

[0029] In a specific implementation, a corresponding delayed consumption message is generated by a producer according to the user's consumption demand, and then the producer sends the delayed consumption message asynchronously or non-asynchronously to a delay queue for subsequent processing.

[0030] Step S20, polling the delay queue configured by Redis according to a preset polling method to determine the target polling result; It can be understood that the preset polling method refers to a pre-set active checking mechanism, which obtains the latest status or data of resources by sending requests periodically, and the target polling results include message invalidation results and message execution results.

[0031] In the specific implementation, before consuming the message, a thread is started first, and the data is pulled through the polling method. If the data is no longer available, it means that the data has been executed by the previous task; if the data is available and the execution time has not yet arrived, that is, a new task has updated the execution time, then the current task is invalid; if the execution time has arrived, then the task is executed. In the specific business scenario, the data is taken out from the delay queue and processed, and finally the target polling result is determined.

[0032] In a feasible implementation, step S20 may include steps A21 to A23: Step A21, polling the delay queue configured by Redis according to a preset polling method to obtain a delay message; It is understandable that the data in the delay queue is pulled through a preset polling method to obtain a message of delayed consumption. If the data is no longer available, that is, the data is not pulled through the preset polling method, it means that the data has been executed by the previous task.

[0033] Step A22, determining a corresponding message execution time according to the delayed message; It can be understood that the message execution time refers to the time when the message is expected to be executed. After obtaining the delayed consumption message through a preset polling method, the obtained delayed consumption message is parsed to determine the time when the corresponding message is expected to be executed, and then determine whether to execute the message.

[0034] Step A23, determining the target polling result according to the current polling time and the message execution time.

[0035] It can be understood that the current polling time refers to the current time when the delay queue is polled, and then the current time when the delay queue is polled is compared with the time when the message is expected to be executed, that is, to determine whether the current time reaches the time when the message is expected to be executed, so as to determine the target polling result.

[0036] In a feasible implementation manner, step A23 may include steps B231 to B233: Step B231, comparing the current polling time with the message execution time to obtain a time comparison result; It can be understood that the time comparison result refers to the comparison result of whether the current time reaches the time when the message is expected to be executed.

[0037] In a specific implementation, the current time when polling the delay queue is compared with the time when the message is expected to be executed to determine whether the current time reaches the time when the message is expected to be executed, and finally obtain a comparison result of whether the current time reaches the time when the message is expected to be executed.

[0038] Step B232, when the time comparison result is that the message execution time is less than the current polling time, determining that the target polling result is a message failure result; It can be understood that the message failure result means that if a new task updates the execution time, the current message becomes invalid.

[0039] In a specific implementation, when the time comparison result is that the current time when polling the delay queue is less than the time when the message is expected to be executed, it indicates that the current time when polling the delay queue has not reached the time when the message is expected to be executed, that is, if a new task updates the execution time, the current message is invalid, and the target polling result is determined to be a message invalid result.

[0040] Step B233: When the time comparison result is that the message execution time is greater than or equal to the current polling time, determine that the target polling result is the message execution result.

[0041] It can be understood that the message execution result refers to the result of executing the message when the execution time has arrived.

[0042] In a specific implementation, when the time comparison result is that the current time when polling the delay queue is greater than or equal to the time when the message is expected to be executed, it indicates that the current time when polling the delay queue has reached the time when the message is expected to be executed, that is, the execution time has been reached, then the task is executed to determine that the target polling result is the message execution result.

[0043] Step S30: performing message processing according to the target polling result.

[0044] In a specific implementation, when the target polling result is a message execution result, it indicates that the execution time has arrived, and then the task is executed, and then in a specific business scenario, the data is taken out from the delay queue and processed.

[0045] In a feasible implementation, step S30 may include steps A31-A32: Step A31, when the target polling result is a message execution result, parsing the delayed message corresponding to the message execution result to obtain target processing data; It can be understood that the target processing data refers to the data that needs to be processed. When the target polling result is the message execution result, it indicates that the delayed message needs to be processed, and then the corresponding delayed message is parsed, and then the corresponding data that needs to be processed is determined based on the message parsing result.

[0046] Step A32, processing the target processing data to complete message processing.

[0047] It can be understood that corresponding data processing operations are performed on the parsed data to be processed, thereby completing the processing of the delayed message.

[0048] In a feasible implementation manner, step S30 may include steps B31 to B34: Step B31, obtaining consumption delay time, consumption rate and task processing quantity; It can be understood that consumption delay time refers to the time difference from task generation to task processing by the consumer, consumption rate refers to the number of tasks processed by the consumer per unit time, and task processing number refers to the total number of tasks processed by the consumer within a certain period of time.

[0049] In the specific implementation, the configuration module can collect statistics on the load of each node during the operation of the Redis client, including the time difference from task generation to task processing by the consumer, the number of tasks processed by the consumer per unit time, and the total number of tasks processed by the consumer in a certain period of time.

[0050] Step B32, analyzing the consumption delay time, the consumption rate, and the number of task processing to obtain a consumption analysis result; It can be understood that the consumption analysis results refer to a series of conclusions drawn after comprehensive analysis of indicators such as consumption delay time, consumption rate, and number of task processing.

[0051] In the specific implementation, by analyzing the time difference from task generation to task processing by the consumer, the number of tasks processed by the consumer per unit time, and the total number of tasks processed by the consumer in a certain period of time, a series of conclusions are drawn after comprehensive analysis of indicators such as consumption delay time, consumption rate, and number of task processing, namely the consumption analysis results.

[0052] Step B33, generating corresponding target optimization suggestion information according to the consumption analysis result; In specific implementations, target optimization recommendation information refers to recommendation information on the performance, health status, and potential problems of the optimization system. It generates corresponding recommendation information on the performance, health status, and potential problems of the optimization system by drawing a series of conclusions after comprehensive analysis of indicators such as consumption delay time, consumption rate, and number of task processing.

[0053] Step B34, optimizing the configuration information according to the target optimization suggestion information to obtain optimized configuration information.

[0054] In the specific implementation, the system configuration information is optimized by optimizing the system's performance, health status and recommendation information of potential problems to obtain the optimized configuration information. For example, if the consumption rate is lower than expected, it is recommended to increase the number of consumers to improve the system's processing capacity; if the task processing time is too long, it is recommended to optimize the task processing logic to reduce the processing time of a single task; if the system resources (such as CPU, memory, network bandwidth) are insufficient, it is recommended to increase the system resources to improve the overall performance of the system.

[0055] It should be noted that the independent delay queue configured based on Redis in this embodiment is characterized by providing two modes: single-point producer and load-balanced multi-producer, which are adapted to systems with different data scales. And using a stable, configurable Redis client, it can be highly adapted to system applications in a variety of different scenarios, suitable for order timeout processing, scheduled task scheduling, risk control review, appointment services and other scenarios that require timing or time delay; and provides an independent implementation without relying on external systems. This implementation isolates the high complexity of the zset delay queue from the external system, avoids the coupling between the system and the delay queue, and changes to the delay queue will not have a direct impact on the external system; based on the persistence and replication functions of Redis, it can ensure that data will not be lost when the server restarts or fails. The delay queue supports custom delay time, and can set a precise delay time or delay according to a time period.

[0056] This embodiment publishes a delayed message to a delay queue; polls the delay queue configured by Redis according to a preset polling method to determine the target polling result; and processes the message according to the target polling result. By implementing a delay queue based on Redis, it is possible to effectively reduce the consumption and dependence on system resources, implement this function independently of an external system, and horizontally expand to implement a multi-cluster mode, which is suitable for scenarios with large amounts of data, thereby ensuring the orderliness of the data, the uniqueness of the message, and the reliability. It can also be applied to specific business scenarios such as order timeout processing, scheduled task scheduling, risk control review, and appointment services, and is implemented from the aspects of timing and time delay.

[0057] Based on the first embodiment of the present application, in the second embodiment of the present application, the same or similar contents as those in the above-mentioned embodiment 1 can be referred to the above introduction, and will not be repeated in the following. Figure 3 Before step S10, the message processing method based on Redis also includes steps S01 to S03: Step S01, performing initialization processing according to configuration information to determine the initialization state; It can be understood that the configuration information includes information such as the master node connection pool size and the number of idle connections and the slave node connection pool size and the number of idle connections, and the initialization status refers to the status of whether the initialization is completed.

[0058] In the specific implementation, it mainly involves the configuration of Redis node publishing and connection pool, configuration of connection pool, master node connection pool size and number of idle connections, slave node connection pool size and number of idle connections, etc. Redis cluster mode combines different Redis strategies and different levels of protection to ensure the disaster recovery capability of the system to a higher degree, and finally determines whether the initialization is completed, that is, the initialization state.

[0059] Step S02, when the initialization state is the initialization completion state, determining the load balancing state according to the current data volume and the data volume threshold; In a specific implementation, the current data volume refers to the amount of data in the current system, the data volume threshold refers to the critical value of the data volume used to determine whether to perform load balancing, and the load balancing status includes the load balancing completion status and the load balancing incomplete status.

[0060] In a specific implementation, when the initialization state is the initialization completion state, the data size in the current system is obtained, and then the data size in the current system is compared with the data size critical value used to determine whether to perform load balancing to determine whether to perform load balancing processing, that is, determine the load balancing state.

[0061] In a feasible implementation, step S02 may include steps A021-A022: Step A021, when the initialization state is the initialization completion state, comparing the current data volume with the data volume threshold; In a specific implementation, when the initialization state is the initialization completion state, the data size in the current system is compared with the data size critical value used to determine whether to perform load balancing to determine the size comparison result of the data size in the current system and the data size critical value used to determine whether to perform load balancing.

[0062] Step A022, when the current data volume is greater than or equal to the data volume threshold, load balancing processing is performed according to a hash algorithm to determine a load balancing state.

[0063] In the specific implementation, the amount of data in the current system is greater than or equal to the data volume critical value used to determine whether to perform load balancing, indicating that the amount of data in the current system is large and load balancing is required. Then, load balancing is performed according to the hash algorithm to determine the load balancing status.

[0064] Step S03, when the load balancing state is the load balancing completion state, execute the step of publishing a delay message to a delay queue.

[0065] In a specific implementation, when the load balancing state is the load balancing completion state, the step of publishing to the delay queue through the producer is executed to perform subsequent operations of processing the delayed message.

[0066] It should be noted that the delay queue module of this embodiment: This module is the core implementation part of the Redis zset delay queue. The production and consumption of messages in the delay queue and the extended load balancing function are all built in this module, and a unified interface is provided for external systems to use. Producer collection: Provides asynchronous or non-asynchronous sending of messages to the message queue, as well as the cancellation of single or batch tasks. The producer bucket collection stores job meta information, including task type, unique jobid, time required to wait for the task, expected time for task execution, specific content of the task, etc. The interface corresponding to the producer can add tasks, delete tasks, and delete tasks in batches; consumer queue: Before consuming the message, start a thread first, and pull data through polling. If the data no longer exists, it means that the data has been executed by the previous task; if the data exists and the execution time has not yet arrived, that is, a new task has updated the execution time, then the current task will fail; if the execution time has arrived, then execute the task, which means taking the data out of the delay queue and processing it in a specific business scenario; the load balancing process is as follows Figure 4 As shown in the figure, load balancing: inherit the main implementation class of the Redis client, customize the initialization, and edit the producer in this process to achieve the function of load balancing. By default, a single point zset corresponds to a single producer. For application scenarios with large data volumes and possible data skew, multiple producers are created during initialization, and the consistent Hash algorithm is used to load balance messages. Multiple producers share the request traffic and ensure uniform data distribution.

[0067] It should be noted that the configuration module in this embodiment: This module is some initial configuration related to the Redis client. This part is separated independently and provides a set of default configurations. The external system can directly use this set of default configurations, or change the configuration according to actual needs. Connection pool configuration: It is mainly the configuration of Redis node publishing and connection pool, configuring the connection pool, the master node connection pool size and the number of idle connections, the slave node connection pool size and the number of idle connections, etc. The cluster mode of Redis combines different strategies and different levels of guarantees of Redis to ensure the disaster recovery capability of the system to a higher degree; switch configuration: The delay queue core module realizes single-point producers and load-balanced multi-producers. The configuration module provides a switch to switch these two modes so that the application can choose the appropriate production method according to the actual scenario; load statistics: The configuration module can count the load conditions of each node during the operation of the Redis client, including consumption delay time, consumption rate, number of tasks, etc.

[0068] This embodiment determines the initialization state by performing initialization processing according to the configuration information; when the initialization state is the initialization completion state, the load balancing state is determined according to the current data volume and the data volume threshold; when the load balancing state is the load balancing completion state, the step of publishing a delayed message to the delay queue is executed. By providing a load balancing function, data skew in the Redis cluster mode is avoided and the stability of the system is improved. At the same time, load balancing also improves the performance of the delay queue and the availability of the system, which is suitable for scenarios such as order flash sales that have high requirements on data volume.

[0069] For example, to help understand the implementation process of the message processing method based on Redis obtained by combining this embodiment with the above-mentioned embodiment 1, please refer to Figure 5 , Figure 5 This paper provides a brief flow chart of a message processing method based on Redis, specifically: the process of delaying message consumption using the Redis client. First, configure the appropriate connection pool and number of connections according to the specific business scenario, and select the single-point producer or load-balanced multi-producer mode based on the system traffic. The messages generated by the producer will be routed to a delay queue and the delay consumption time will be specified. The consumer will periodically poll and pull the message at the head of the queue and determine whether the message has reached the execution time. The Lua script is used to operate Redis. For messages that have not reached the execution time, they will continue to stay in the delay queue, while messages that have reached the execution time will be taken out of the delay queue and consumed. Then the consumer can consume these messages and process the actual business logic.

[0070] It should be noted that the above examples are only used to understand the present application and do not constitute a limitation on the message processing method based on Redis of the present application. More simple transformations based on this technical concept are all within the scope of protection of the present application.

[0071] This application also provides a message processing device based on Redis, please refer to Figure 6 , the Redis-based message processing device includes: A publishing module 10, used for publishing a delayed message to a delay queue; The polling module 20 is used to poll the delay queue configured by Redis according to a preset polling method to determine the target polling result; The processing module 30 is used to perform Redis-based message processing according to the target polling result.

[0072] Optionally, the polling module 20 is further configured to: Poll the delay queue configured in Redis according to the preset polling method to obtain the delay message; Determine a corresponding message execution time according to the delayed message; The target polling result is determined according to the current polling time and the message execution time.

[0073] Optionally, the polling module 20 is further configured to: Compare the current polling time with the message execution time to obtain a time comparison result; When the time comparison result is that the message execution time is less than the current polling time, determining that the target polling result is a message failure result; When the time comparison result is that the message execution time is greater than or equal to the current polling time, it is determined that the target polling result is the message execution result.

[0074] Optionally, the processing module 30 is further used for: When the target polling result is a message execution result, parsing the delayed message corresponding to the message execution result to obtain target processing data; The target processing data is processed to complete message processing.

[0075] Optionally, the publishing module 10 is further used for: Perform initialization processing according to the configuration information and determine the initialization state; When the initialization state is an initialization completion state, determining a load balancing state according to a current data volume and a data volume threshold; When the load balancing state is a load balancing completion state, a step of publishing a delay message to a delay queue is performed.

[0076] Optionally, the publishing module 10 is further used for: When the initialization state is an initialization completion state, comparing the current data volume with a data volume threshold; When the current data volume is greater than or equal to the data volume threshold, load balancing processing is performed according to a hash algorithm to determine a load balancing state.

[0077] Optionally, the processing module 30 is further used for: Get consumption delay time, consumption rate and number of tasks processed; Analyze the consumption delay time, the consumption rate, and the number of task processing to obtain a consumption analysis result; Generate corresponding target optimization suggestion information according to the consumption analysis result; The configuration information is optimized according to the target optimization suggestion information to obtain optimized configuration information.

[0078] The message processing device based on Redis provided by the present application adopts the message processing method based on Redis in the above embodiment, which can solve the technical problem of low reliability of data processing in the existing delay queue. Compared with the prior art, the beneficial effects of the message processing device based on Redis provided by the present application are the same as the beneficial effects of the message processing method based on Redis provided by the above embodiment, and other technical features in the message processing device based on Redis are the same as the features disclosed in the above embodiment method, which will not be repeated here.

[0079] The present application provides a Redis-based message processing device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the Redis-based message processing method in the above-mentioned embodiment 1.

[0080] Reference below Figure 7, which shows a schematic diagram of the structure of a Redis-based message processing device suitable for implementing the embodiment of the present application. The Redis-based message processing device in the embodiment of the present application may include but is not limited to mobile terminals such as mobile phones, laptops, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 7 The Redis-based message processing device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0081] like Figure 7 As shown, the message processing device based on Redis may include a processing device 1001 (such as a central processing unit, a graphics processing unit, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. In RAM1004, various programs and data required for the operation of the message processing device based on Redis are also stored. The processing device 1001, ROM1002 and RAM1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems can be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touchpad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 can allow the Redis-based message processing device to communicate with other devices wirelessly or by wire to exchange data. Although the figure shows a Redis-based message processing device with various systems, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems can be implemented or provided alternatively.

[0082] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.

[0083] The Redis-based message processing device provided by the present application adopts the Redis-based message processing method in the above embodiment, which can solve the technical problem of low reliability of data processing in the existing delay queue. Compared with the prior art, the beneficial effects of the Redis-based message processing device provided by the present application are the same as the beneficial effects of the Redis-based message processing method provided in the above embodiment, and the other technical features of the Redis-based message processing device are the same as the features disclosed in the previous embodiment method, which will not be repeated here.

[0084] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.

[0085] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

[0086] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, computer programs) stored thereon, and the computer-readable program instructions are used to execute the Redis-based message processing method in the above-mentioned embodiment.

[0087] The computer-readable storage medium provided in the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems or devices, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM: Random Access Memory), a read-only memory (ROM: Read Only Memory), an erasable programmable read-only memory (EPROM: Erasable Programmable Read Only Memory or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM: CD-Read Only Memory), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program, which may be used by or in combination with an instruction execution system, system or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency: Radio Frequency), etc., or any suitable combination of the above.

[0088] The computer-readable storage medium may be included in a Redis-based message processing device; or may exist independently without being assembled into a Redis-based message processing device.

[0089] The above-mentioned computer-readable storage medium carries one or more programs. When the above-mentioned one or more programs are executed by a Redis-based message processing device, the Redis-based message processing device: publishes delayed messages to a delay queue; polls the delay queue configured for Redis according to a preset polling method to determine a target polling result; and processes messages according to the target polling result.

[0090] Computer program code for performing the operations of the present application may be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, C++, and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0091] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0092] The modules involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.

[0093] The readable storage medium provided by the present application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned message processing method based on Redis, and can solve the technical problem of low reliability of data processing in the existing delay queue. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided by the present application are the same as the beneficial effects of the message processing method based on Redis provided by the above-mentioned embodiment, and will not be repeated here.

[0094] The present application also provides a computer program product, including a computer program, which implements the steps of the above-mentioned Redis-based message processing method when executed by a processor.

[0095] The computer program product provided by the present application can solve the technical problem of low reliability of data processing in the existing delay queue. Compared with the prior art, the beneficial effects of the computer program product provided by the present application are the same as the beneficial effects of the message processing method based on Redis provided in the above embodiment, which will not be repeated here.

[0096] The above descriptions are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect applications in other related technical fields are included in the patent protection scope of the present application.

Claims

1. A message processing method based on Redis, characterized in that: The Redis-based message processing method includes: Publish delayed messages to the delay queue; Poll the delay queue configured by Redis according to the preset polling method to determine the target polling result; Message processing is performed according to the target polling result.

2. The method according to claim 1, characterized in that The step of polling the delay queue configured by Redis according to the preset polling method to determine the target polling result includes: Poll the delay queue configured in Redis according to the preset polling method to obtain the delay message; Determine a corresponding message execution time according to the delayed message; The target polling result is determined according to the current polling time and the message execution time.

3. The method according to claim 2, characterized in that Determining the target polling result according to the current polling time and the message execution time includes: Compare the current polling time with the message execution time to obtain a time comparison result; When the time comparison result is that the message execution time is less than the current polling time, determining that the target polling result is a message failure result; When the time comparison result is that the message execution time is greater than or equal to the current polling time, it is determined that the target polling result is the message execution result.

4. The method according to claim 1, characterized in that The step of performing message processing according to the target polling result comprises: When the target polling result is a message execution result, parsing the delayed message corresponding to the message execution result to obtain target processing data; The target processing data is processed to complete message processing.

5. The method according to claim 1, characterized in that Before the step of publishing the delayed message to the delay queue, the method further includes: Perform initialization processing according to the configuration information and determine the initialization state; When the initialization state is an initialization completion state, determining a load balancing state according to a current data volume and a data volume threshold; When the load balancing state is a load balancing completion state, a step of publishing a delay message to a delay queue is performed.

6. The method according to claim 5, characterized in that The step of determining the load balancing state according to the current data volume and the data volume threshold when the initialization state is the initialization completion state includes: When the initialization state is an initialization completion state, comparing the current data volume with a data volume threshold; When the current data volume is greater than or equal to the data volume threshold, load balancing processing is performed according to a hash algorithm to determine a load balancing state.

7. The method according to any one of claims 1 to 6, characterized in that After the step of performing message processing according to the target polling result, the method further includes: Get consumption delay time, consumption rate and number of tasks processed; Analyze the consumption delay time, the consumption rate, and the number of task processing to obtain a consumption analysis result; Generate corresponding target optimization suggestion information according to the consumption analysis result; The configuration information is optimized according to the target optimization suggestion information to obtain optimized configuration information.

8. A message processing device based on Redis, characterized in that: The device comprises: A publishing module is used to publish delayed messages to a delay queue; The polling module is used to poll the delay queue configured by Redis according to the preset polling method to determine the target polling result; A processing module is used to process messages according to the target polling result.

9. A message processing device based on Redis, characterized in that: The device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the Redis-based message processing method according to any one of claims 1 to 7.

10. A storage medium, characterized in that: The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the Redis-based message processing method according to any one of claims 1 to 7 are implemented.

Citation Information

Cited By

  • Method and system for optimizing seckilling activity

    CN120711078A

  • Queue management method and device

    CN122420263A