Unlock instant, AI-driven research and patent intelligence for your innovation.

Redis-based asynchronous delay queue implementation method

An implementation method and queue technology, applied in the java field under the microservice architecture, can solve the problems of not supporting distributed operation message persistence, not supporting time precision, etc., and achieve the effects of improving system stability, good scalability, and simplifying development

Pending Publication Date: 2021-11-23
SHANDONG LANGCHAO YUNTOU INFORMATION TECH CO LTD
View PDF0 Cites 0 Cited by
  • Summary
  • Abstract
  • Description
  • Claims
  • Application Information

AI Technical Summary

Problems solved by technology

[0012] Disadvantages: queue messages are in jvm memory, and do not support distributed operation and message persistence;
[0015] Disadvantage: does not support arbitrary time precision, only supports delayed messages of a specific level;
[0018] Disadvantage: messages with the same delay must be thrown in the same queue

Method used

the structure of the environmentally friendly knitted fabric provided by the present invention; figure 2 Flow chart of the yarn wrapping machine for environmentally friendly knitted fabrics and storage devices; image 3 Is the parameter map of the yarn covering machine
View more

Image

Smart Image Click on the blue labels to locate them in the text.
Viewing Examples
Smart Image
  • Redis-based asynchronous delay queue implementation method

Examples

Experimental program
Comparison scheme
Effect test

Embodiment Construction

[0054] The present invention will be described in further detail below in conjunction with the accompanying drawings and embodiments.

[0055] A redis-based asynchronous delay queue implementation method, the implementation process of the method is as follows:

[0056] 1. Enqueue operation: ZADD KEY timestamp task, add the task that needs to be processed, delay the processing time according to its needs as Score to ZSet, where the time complexity of ZAdd of Redis is O(logN), N is the number of elements in ZSet number, so the enqueue operation can be performed relatively efficiently.

[0057] 2. Initiate a process to query the element with the smallest Score in the ZSet through the ZREANGEBYSCORE method at regular intervals (for example, every second). The specific operation is: ZRANGEBYSCORE KEY-inf+inf limit 0 1WITHSCORES. There are two cases of query results:

[0058] a. The queried score is less than or equal to the current timestamp, indicating that the task needs to be ex...

the structure of the environmentally friendly knitted fabric provided by the present invention; figure 2 Flow chart of the yarn wrapping machine for environmentally friendly knitted fabrics and storage devices; image 3 Is the parameter map of the yarn covering machine
Login to View More

PUM

No PUM Login to View More

Abstract

The invention discloses a redis-based asynchronous delay queue realization method, which is characterized in that the method realizes a delay queue based on Redis and springboot, and the specific realization comprises the following contents that: a task needing to be processed is added as a Score into a ZSet according to the required delay processing time of the task; the time complexity of ZAdd of Redis is O (logN), and N is the number of elements in ZSet; and a process is initiated, and the element with the minimum Score in the ZSet is queried through a ZREANGEBYSCORE method at regular time. According to the method, development of back-end applications is simplified, the system performance of a traditional mode is improved, the system stability is further improved, and the method is more flexible due to the switching mode; the queue realized by using the Redis has good expansibility, the change of requirements and the expansion of services can be conveniently dealt with, and when a large number of timed tasks need to be realized, the delay queue can be considered to be used for realizing, so that codes have better expansibility.

Description

technical field [0001] The invention relates to the technical field of java under the microservice architecture, and specifically provides a redis-based asynchronous delay queue implementation method. Background technique [0002] Delay queue is a technical solution that is often encountered and needs to be used in the daily development process. First, a queue is a first-in, first-out data structure. The elements in the normal queue are ordered, and the elements that enter the queue first will be taken out first for consumption; [0003] The biggest difference between the delay queue and the ordinary queue is reflected in its delay attribute. The elements of the ordinary queue are first in, first out, and are processed in the order of entering the queue, while the elements in the delay queue will be specified when entering the queue. A delay time indicating that it wants to be able to process after the specified time has elapsed. In a sense, the structure of the delay que...

Claims

the structure of the environmentally friendly knitted fabric provided by the present invention; figure 2 Flow chart of the yarn wrapping machine for environmentally friendly knitted fabrics and storage devices; image 3 Is the parameter map of the yarn covering machine
Login to View More

Application Information

Patent Timeline
no application Login to View More
Patent Type & Authority Applications(China)
IPC IPC(8): G06F9/54G06F9/52
CPCG06F9/546G06F9/524G06F2209/548
Inventor 刘建邦徐士强董玉全
Owner SHANDONG LANGCHAO YUNTOU INFORMATION TECH CO LTD