CN114116247A - Redis-based message processing method, device, system, server and medium - Google Patents

Redis-based message processing method, device, system, server and medium Download PDF

Info

Publication number
CN114116247A
CN114116247A CN202110359735.3A CN202110359735A CN114116247A CN 114116247 A CN114116247 A CN 114116247A CN 202110359735 A CN202110359735 A CN 202110359735A CN 114116247 A CN114116247 A CN 114116247A
Authority
CN
China
Prior art keywords
delay
target
message
queue
task
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202110359735.3A
Other languages
Chinese (zh)
Inventor
郭思聪
迟彪
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Jingdong Tuoxian Technology Co Ltd
Original Assignee
Beijing Jingdong Tuoxian Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Jingdong Tuoxian Technology Co Ltd filed Critical Beijing Jingdong Tuoxian Technology Co Ltd
Priority to CN202110359735.3A priority Critical patent/CN114116247A/en
Publication of CN114116247A publication Critical patent/CN114116247A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/546Message passing systems or structures, e.g. queues
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2228Indexing structures
    • G06F16/2255Hash tables
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • G06F16/24552Database cache management
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2457Query processing with adaptation to user needs
    • G06F16/24578Query processing with adaptation to user needs using ranking

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • Software Systems (AREA)
  • Computational Linguistics (AREA)
  • Computer And Data Communications (AREA)

Abstract

The embodiment of the disclosure discloses a message processing method, a device, a system, a server and a medium based on Redis. One embodiment of the method comprises: in response to receiving a delay message task, determining a delay queue set for receiving the delay message task as a target delay queue set, wherein the target delay queue set comprises a delay queue set which is selected from at least two preset delay queue sets and matched with the delay message task; selecting a target process from the process set matched with the target delay queue set; querying a delay message task to be processed in the target delay queue through the target process; and sending the delay message task to be processed to a preset message consumption queue. The implementation mode reduces information accumulation in the delay queue set, avoids obvious reduction of message processing efficiency, and improves the efficiency and reliability of the whole system.

Description

Redis-based message processing method, device, system, server and medium
Technical Field
Embodiments of the present disclosure relate to the field of computer technologies, and in particular, to a message processing method, apparatus, system, server, and medium based on Redis.
Background
With the rapid development of internet technology, the size of data is also getting larger and larger. Accordingly, new challenges are posed to the processing efficiency and availability of databases.
In the prior art, the cache database Redis provides a data structure of a set, and elements in the set are queried regularly (for example, every second) for consumption through an Event process. However, with the development of services, the number of enqueued message data is gradually increased, and the concurrency is correspondingly increased. The problem of data accumulation is often caused after a set corresponding to one KEY (KEY) stores more messages, and the speed of enqueuing operation and query operation is further influenced; and the set corresponds to the Event process one by one, so that the Event process has the problem of single-point failure, and the high availability of the whole system cannot be ensured.
Disclosure of Invention
The embodiment of the disclosure provides a message processing method, device, system, server and medium based on Redis.
In a first aspect, an embodiment of the present disclosure provides a method for message processing based on Redis, where the method includes: in response to receiving the delay message task, determining a delay queue set for receiving the delay message task as a target delay queue set, wherein the target delay queue set comprises a delay queue set which is selected from at least two preset delay queue sets and matched with the delay message task; selecting a target process from a process set matched with the target delay queue set; querying a delay message task to be processed in a target delay queue through a target process; and sending the delay message task to be processed to a preset message consumption queue.
In some embodiments, the delay message tasks in the set of delay queues correspond to delay time fractions for characterizing delay processing time; the querying a to-be-processed delayed message task in the target delay queue through the target process includes: the following query steps are performed: selecting the minimum delay time fraction from the target delay queue set as a target fraction; and in response to determining that the time indicated by the target score is not later than the time indicated by the current timestamp, determining the delayed message task corresponding to the target score as the delayed message task to be processed.
In some embodiments, the querying, by the target process, the pending deferred message task in the target deferred queue further includes: and in response to determining that the time indicated by the target score is later than the time indicated by the current timestamp, continuing to perform the querying step after sleeping for a preset time.
In some embodiments, the target process includes a temporary node (leader) obtained based on Zookeeper election.
In a second aspect, an embodiment of the present disclosure provides a message processing apparatus based on Redis, the apparatus including: the device comprises a determining unit, a delay unit and a delay unit, wherein the determining unit is configured to respond to the received delay message task and determine a delay queue set for receiving the delay message task as a target delay queue set, and the target delay queue set comprises a delay queue set which is selected from at least two preset delay queue sets and matched with the delay message task; a selecting unit configured to select a target process from a set of processes matching the set of target delay queues; the query unit is configured to query the delay message task to be processed in the target delay queue through the target process; and the sending unit is configured to send the delay message task to be processed to a preset message consumption queue.
In some embodiments, the delayed message tasks in the set of delay queues correspond to a fraction of delay time used to characterize delay processing time. The querying element is further configured to: the following query steps are performed: selecting the minimum delay time fraction from the target delay queue set as a target fraction; and in response to determining that the time indicated by the target score is not later than the time indicated by the current timestamp, determining the delayed message task corresponding to the target score as the delayed message task to be processed.
In some embodiments, the querying element is further configured to: and in response to determining that the time indicated by the target score is later than the time indicated by the current timestamp, continuing to perform the querying step after sleeping for a preset time.
In some embodiments, the target process includes a temporary node obtained based on Zookeeper election.
In a third aspect, an embodiment of the present application provides a message processing system based on Redis, where the system includes: the producer is configured to obtain information of at least two preset delay queue sets; selecting a target delay queue set from at least two delay queue sets according to the information; storing the produced delay message task into a target delay queue set; a message processing side configured to perform the method as described in any of the first aspects; the consumer is configured to select a delay message task to be processed from the message consumption queue; and processing the selected to-be-processed delay message task.
In some embodiments, the at least two sets of delay queues include two sets of delay queues corresponding to the same key.
In some embodiments, the information of the at least two sets of delay queues includes a key; and the producer is further configured to: determining hash values corresponding to keys of at least two delay queue sets; distributing the hash value corresponding to the key to a preset hash ring; determining a hash value corresponding to the generated delayed message task in a manner of being consistent with the hash value corresponding to the generated key; mapping a hash value corresponding to the delayed message task to a hash ring; and selecting a target delay queue set according to the relative relation between the position of the hash value corresponding to the delay message task mapped to the hash ring and the position of the hash value corresponding to the key distributed to the preset hash ring.
In a fourth aspect, an embodiment of the present application provides a server, where the server includes: one or more processors; a storage device having one or more programs stored thereon; when the one or more programs are executed by the one or more processors, the one or more processors are caused to implement the method as described in any implementation of the first aspect.
In a fifth aspect, the present application provides a computer-readable medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the method as described in any implementation manner of the first aspect.
According to the message processing method, device, system, server and medium based on Redis provided by the embodiment of the disclosure, the message amount in each delay queue set is reduced when the data amount is greatly increased through at least two preset delay queue sets, so that the information accumulation in the delay queue sets is reduced, and the obvious reduction of the message processing efficiency is avoided. And moreover, the process matched with the target delay queue set is improved into the process set, so that single-point failure of the process is avoided, and the efficiency and the reliability of the whole system are improved.
Drawings
Other features, objects and advantages of the disclosure will become more apparent upon reading of the following detailed description of non-limiting embodiments thereof, made with reference to the accompanying drawings in which:
FIG. 1 is an exemplary system architecture diagram in which one embodiment of the present disclosure may be applied;
FIG. 2 is a flow diagram for one embodiment of a Redis-based message processing method according to the present disclosure;
FIG. 3 is a schematic diagram of one application scenario of a Redis-based message processing method according to an embodiment of the present disclosure;
FIG. 4 is a schematic block diagram illustrating one embodiment of a Redis-based message processing apparatus according to the present disclosure;
FIG. 5 is a timing diagram of interactions between various devices in one embodiment of a Redis-based message processing system according to the present application.
FIG. 6 is a schematic block diagram of an electronic device suitable for use in implementing embodiments of the present application.
Detailed Description
The present disclosure is described in further detail below with reference to the accompanying drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the relevant invention and not restrictive of the invention. It should be noted that, for convenience of description, only the portions related to the related invention are shown in the drawings.
It should be noted that, in the present disclosure, the embodiments and features of the embodiments may be combined with each other without conflict. The present disclosure will be described in detail below with reference to the accompanying drawings in conjunction with embodiments.
Fig. 1 illustrates an exemplary architecture 100 to which the Redis-based message processing method or the Redis-based message processing apparatus of the present disclosure may be applied.
As shown in fig. 1, the system architecture 100 may include end devices 101, 102, 103, a network 104, and a server cluster 105. The server cluster 105 may include servers 1051, 1052, 1053, 1054, and 1055. The network 104 serves to provide a medium of communication links between the terminal devices 101, 102, 103 and the server cluster 105. Network 104 may include various connection types, such as wired, wireless communication links, or fiber optic cables, to name a few.
The terminal devices 101, 102, 103 interact with the server cluster 105 via the network 104 to receive or send messages or the like. The terminal devices 101, 102, 103 may have various communication client applications installed thereon, such as a web browser application, a shopping application, a search application, an instant messaging tool, a mailbox client, a database, and the like.
The terminal apparatuses 101, 102, and 103 may be hardware or software. When the terminal devices 101, 102, 103 are hardware, they may be various electronic devices having a display screen and supporting human-computer interaction, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, and the like. When the terminal apparatuses 101, 102, 103 are software, they can be installed in the electronic apparatuses listed above. It may be implemented as multiple pieces of software or software modules (e.g., software or software modules used to provide distributed services) or as a single piece of software or software module. And is not particularly limited herein.
The server cluster 105 may be a server providing various services, such as a background server providing support for database-like applications on the terminal devices 101, 102, 103. The backend server may analyze the received task request and execute corresponding processing according to the request (e.g., the servers 1051 and 1052 generate tasks, the server 1053 performs task management, and the servers 1054 and 1055 execute tasks).
The server may be hardware or software. When the server is hardware, it may be implemented as a distributed server cluster formed by multiple servers, or may be implemented as a single server. When the server is software, it may be implemented as multiple pieces of software or software modules (e.g., software or software modules used to provide distributed services), or as a single piece of software or software module. And is not particularly limited herein.
It should be noted that the message processing method based on Redis provided by the embodiment of the present disclosure is generally executed by the server 1053, and accordingly, the message processing apparatus based on Redis is generally disposed in the server 1053.
It should be understood that the number of terminal devices, networks, and servers in fig. 1 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
With continued reference to FIG. 2, a flow 200 of one embodiment of a Redis-based message processing method in accordance with the present disclosure is shown. The message processing method based on Redis comprises the following steps:
in step 201, in response to receiving the delayed message task, determining the set of delay queues receiving the delayed message task as a target set of delay queues.
In the present embodiment, in response to receiving a delay message task, an execution subject of the Redis-based message processing method (e.g., the server 1053 shown in fig. 1) may determine a set of delay queues receiving the delay message task as a target set of delay queues in various ways. The target delay queue set may include a delay queue set selected from at least two preset delay queue sets and matched with the delay message task.
It should be noted that the delay message task can be flexibly set according to different application scenarios. As an example, the delayed message task may be to cancel the order automatically if no payment is made within 30 minutes after the order is successful. As another example, the delayed message task may be to push a short message to the corresponding user terminal after waiting for 1 minute in response to confirming that the order placement is successful.
In this embodiment, the Redis architecture may include a plurality of delay queue sets. As an example, each key may correspond to multiple sets of delay queues. The producer of the delayed message task may select a set of delay queues matching the delayed message task from the plurality of sets of delay queues as the target set of delay queues. As an example, the set of delay queues may be a set data type in Redis.
In some optional implementations of the present embodiment, the delay message task in the delay queue set may correspond to a delay time fraction used for characterizing the delay processing time. The delay time fraction may include various forms. As an example, the set of delay queues described above may be a Zset (ordered set) data type in Redis.
Step 202, selecting a target process from the process set matched with the target delay queue set.
In this embodiment, the execution subject may select a target process from the process set matching the target delay queue set determined in step 201 in various ways. The delay queue sets of the at least two delay queue sets may each correspond to a process set composed of a plurality of processes (e.g., Event processes).
In this embodiment, the execution subject may first determine a process set corresponding to the target delay queue set as the process set matching the target delay queue set. Then, the execution subject may select a target process from the matched process set in various ways. As an example, the execution subject may arbitrarily select a process from the matched process set as a target process. As another example, the execution subjects may also be sequentially selected according to the order of the processes in the matched process set.
In some optional implementations of this embodiment, the target process may include a temporary node obtained based on Zookeeper election. Therefore, the execution subject may select a temporary node obtained based on Zookeeper election from the process set matched with the target delay queue set as the target process.
Based on the optional implementation manner, the condition of message accumulation in the delay queue set caused by the fact that the delay queue set only corresponds to one process (such as an Event process) in the prior art after being down can be avoided. Through the Zookeeper election mechanism, the problem that after the original running process fails, a new process can be reselected to continue processing the messages in the delay queue set is guaranteed, and therefore the reliability of the system is improved.
Step 203, the target process queries the delay message task to be processed in the target delay queue.
In this embodiment, the execution subject may query the target delay queue for the pending delay message task through the target process selected in step 202 in various ways. As an example, the execution main body may determine which delayed message tasks are to be processed according to the delay time corresponding to the to-be-processed delayed message task.
In some optional implementations of this embodiment, based on that the delayed message tasks in the set of delay queues correspond to delay time fractions used for characterizing delay processing time, the execution subject may query the target delay queue for the delayed message task to be processed through the target process according to the following steps:
in a first step, the following query steps are performed: and selecting the minimum delay time fraction from the target delay queue set as a target fraction.
In these implementations, the execution entity may select the smallest delay time score from the target set of delay queues as the target score in various ways. As an example, when the target delay queue belongs to the Zset type, the execution main body may directly select a delay time score corresponding to a first element in the target delay queue.
And secondly, in response to the fact that the time indicated by the target score is not later than the time indicated by the current timestamp, determining the delayed message task corresponding to the target score as a delayed message task to be processed.
In these implementations, in response to determining that the time indicated by the target score is not later than the time indicated by the current timestamp, the execution main body may determine the delayed message task corresponding to the target score selected in the first step as the delayed message task to be processed.
Optionally, the executing main body may further continue to perform the following steps:
and thirdly, in response to the fact that the time indicated by the target score is later than the time indicated by the current timestamp, continuing to execute the query step after sleeping for a preset time.
In these implementations, in response to determining that the target score indicates a time later than the time indicated by the current timestamp, the execution agent may continue to execute the querying step at a preset time interval.
Based on the optional implementation manner, the query of the delay message task to be processed can be realized according to the task execution time indicated by the corresponding delay time fraction, so that the query efficiency of the delay message task is improved.
And step 204, sending the delay message task to be processed to a preset message consumption queue.
In this embodiment, the execution subject may send the pending deferred message task queried in step 203 to a preset message consumption queue in various ways. The preset message consumption queue can be used for storing the delay message tasks to be processed.
With continued reference to fig. 3, fig. 3 is a schematic diagram of an application scenario of a Redis-based message processing method according to an embodiment of the present disclosure. In the application scenario of fig. 3, the server 301 sends a delayed message task "60 s post texting" to the server 303 (as shown in fig. 302). In response to receiving the delayed message task 302, the server 303 determines a set of delay queues (e.g., shown as 304) that received the delayed message task 302 as a set of target delay queues. Server 303 may then select a target process from the set of processes that match the set of target delay queues (e.g., as shown at 305). Next, the server 303 may query the target set of delay queues 304 for pending delay message tasks through the target process 305. The server 303 may then send the pending deferred message task 302 to a pre-defined message consumption queue 306.
At present, one of the prior arts generally refers to that elements in a set provided by Redis are queried by an Event process at regular time (for example, every second) for consumption, so that the message processing efficiency is significantly reduced when the data volume is greatly increased, and the Event process has a single point failure problem. In the method provided by the above embodiment of the present disclosure, the message amount in each delay queue set is reduced when the data amount is greatly increased by using at least two preset delay queue sets, so that the information accumulation in the delay queue sets is reduced, and the obvious reduction of the message processing efficiency is avoided. And moreover, the process matched with the target delay queue set is improved into the process set, so that single-point failure of the process is avoided, and the efficiency and the reliability of the whole system are improved.
With further reference to fig. 4, as an implementation of the methods shown in the above-mentioned figures, the present disclosure provides an embodiment of a message processing apparatus based on Redis, which corresponds to the method embodiment shown in fig. 2, and which may be specifically applied in various electronic devices.
As shown in fig. 4, the message processing apparatus 400 based on Redis provided in the present embodiment includes a determining unit 401, a selecting unit 402, an inquiring unit 403, and a sending unit 404. The determining unit 401 is configured to determine, in response to receiving a delay message task, a delay queue set for receiving the delay message task as a target delay queue set, where the target delay queue set includes a delay queue set matched with the delay message task and selected from at least two preset delay queue sets; a selecting unit 402 configured to select a target process from a set of processes matching the set of target delay queues; a query unit 403 configured to query the target delay queue for a pending delay message task by the target process; a sending unit 404 configured to send the pending deferred message task to a preset message consumption queue.
In the present embodiment, in the message processing apparatus 400 based on Redis: the specific processing of the determining unit 401, the selecting unit 402, the querying unit 403, and the sending unit 404 and the technical effects thereof can refer to the related descriptions of step 201, step 202, step 203, and step 204 in the corresponding embodiment of fig. 2, which are not described herein again.
In some optional implementations of the present embodiment, the delay message task in the delay queue set may correspond to a delay time fraction used for characterizing the delay processing time. The querying unit 403 may be further configured to: the following query steps are performed: selecting the minimum delay time fraction from the target delay queue set as a target fraction; and in response to determining that the time indicated by the target score is not later than the time indicated by the current timestamp, determining the delayed message task corresponding to the target score as the delayed message task to be processed.
In some optional implementations of this embodiment, the querying unit 403 may be further configured to: and in response to determining that the time indicated by the target score is later than the time indicated by the current timestamp, continuing to perform the querying step after sleeping for a preset time.
In some optional implementations of this embodiment, the target process may include a temporary node obtained based on Zookeeper election.
The apparatus provided in the foregoing embodiment of the present disclosure reduces the message amount in each delay queue set when the data amount is greatly increased through at least two preset delay queue sets, thereby reducing information accumulation in the delay queue sets and avoiding an obvious reduction in message processing efficiency. And moreover, the process matched with the target delay queue set is improved into the process set, so that single-point failure of the process is avoided, and the efficiency and the reliability of the whole system are improved.
With further reference to FIG. 5, a timing diagram 500 of interactions between various devices in one embodiment of a Redis-based message processing method is illustrated. The Redis-based message processing system may include: a producer (e.g., servers 1051, 1052 shown in FIG. 1), a message processing side (e.g., server 1053 shown in FIG. 1), and a consumer (e.g., at least one of servers 1054, 1055 shown in FIG. 1). The producer can be configured to obtain information of at least two preset delay queue sets; selecting a target delay queue set from at least two delay queue sets according to the information; the produced delayed message task is stored in a target delayed queue set. The message processing terminal may be configured to execute the message processing method based on Redis as described in the foregoing embodiments. The consumer can be configured to select a delay message task to be processed from the message consumption queue; and processing the selected to-be-processed delay message task.
In some optional implementations of the embodiment, the at least two sets of delay queues may include two sets of delay queues corresponding to the same key.
In some optional implementations of this embodiment, the information of the at least two sets of delay queues may include a key. The above producer may be further configured to: determining hash values corresponding to keys of at least two delay queue sets; distributing the hash value corresponding to the key to a preset hash ring; determining a hash value corresponding to the generated delayed message task in a manner of being consistent with the hash value corresponding to the generated key; mapping a hash value corresponding to the delayed message task to a hash ring; and selecting a target delay queue set according to the relative relation between the position of the hash value corresponding to the delay message task mapped to the hash ring and the position of the hash value corresponding to the key distributed to the preset hash ring.
As shown in fig. 5, in step 501, the producer obtains information of at least two preset delay queue sets.
In this embodiment, the producer may obtain information of at least two preset delay queue sets through a wired or wireless connection. The information may include an identification of a set of delay queues.
In some optional implementations of this embodiment, the information of the at least two sets of delay queues may include a key. By way of example, delay queue set 1 and delay queue set 2 may each be used to store a value (e.g., 80, 92, 75, etc.) of a key (e.g., student score).
In step 502, based on the information, the producer selects a target set of delay queues from the at least two sets of delay queues.
In this embodiment, the producer may select a target delay queue set from at least two delay queue sets in various ways according to the information obtained in step 501. As an example, the producer may randomly choose a set of target delay queues. As yet another example, the producers may choose in order as indicated by the identifications of the set of delay queues.
In some optional implementations of this embodiment, based on the information of the at least two sets of delay queues including the key, the producer may select a target set of delay queues from the at least two sets of delay queues according to the information obtained in step 501, by:
the first step is to determine hash values corresponding to keys of at least two delay queue sets.
In these implementations, the producer may determine the hash value corresponding to the key of the at least two sets of delay queues in various ways.
Secondly, distributing the hash value corresponding to the key to a preset hash ring;
in these implementations, the producer assigns the hash value corresponding to the key determined in the first step to a preset hash ring in various ways. As an example, the producer may map the hash value corresponding to the determined key to 0 to (2)32-1). Wherein, the arrays can be arranged into a ring shape connected end to end.
And thirdly, determining the hash value corresponding to the produced delayed message task in a mode of consistent hash value corresponding to the key.
In these implementations, the producer may determine the hash value corresponding to the delayed message task in a manner consistent with the first step of generating the hash value.
And fourthly, mapping the hash value corresponding to the delayed message task to a hash ring.
In these implementations, the producer may map the hash value corresponding to the delayed message task determined in the third step to a hash ring preset in the second step.
And fifthly, selecting a target delay queue set according to the relative relation between the position of the hash value corresponding to the delay message task mapped to the hash ring and the position of the hash value corresponding to the key distributed to the preset hash ring.
In these implementations, the producer may select the target delay queue set in various ways according to a relative relationship between a position where the hash value corresponding to the delay message task is mapped to the hash ring and a position where the hash value corresponding to the key is allocated to the preset hash ring. As an example, the producer may start to perform clockwise search by mapping the hash value corresponding to the delayed message task to the position of the hash ring from the fourth step, and determine the delay queue set corresponding to the position where the hash value corresponding to the searched first key is allocated to the preset hash ring as the target delay queue set. Optionally, if the corresponding delay queue set cannot be found after one round of searching, a preset default delay queue set (e.g., a first delay queue set) may be determined as the target delay queue set.
Based on the optional implementation manner, the scheme can ensure that the delay queue set can be dynamically increased or deleted through the mapping of the hash ring, and the capability of the system for providing the service to the outside is not influenced.
In step 503, the producer stores the produced delay message task into the target set of delay queues.
In this embodiment, the producer may store the produced delay message task into the target delay queue set selected in step 502.
In step 504, in response to receiving the delayed message task, the message processing end determines the set of delay queues receiving the delayed message task as the target set of delay queues.
In step 505, the message handler selects a target process from the set of processes matching the target set of delay queues.
In step 506, the message processing end queries the target delay queue for a pending delayed message task through the target process.
In step 507, the message processing side sends the delayed message task to be processed to a preset message consumption queue.
The above steps 504 to 507 are respectively consistent with the steps 201 to 204 and their optional implementation manners in the foregoing embodiment, and the above descriptions for the steps 201 to 204 and their optional implementation manners also apply to the steps 504 to 507, which are not described again here.
In step 508, the consuming side selects a delayed message task to be processed from the message consumption queue.
In this embodiment, the consuming end may select the delayed message task to be processed from the message consumption queue in various ways. As an example, the consumption end sequentially selects the delayed message tasks to be processed according to the sequence of the element arrangement in the queue. As another example, the consuming side may further select one to-be-processed delayed message task according to the number of the consuming sides and each preset number of the elements in the queue.
In step 509, the consuming side processes the selected pending deferred message task.
In this embodiment, the consuming side may process the to-be-processed delayed message task selected in step 508 in a corresponding manner.
In the message processing system based on Redis provided in the above embodiment of the present application, a producer selects a corresponding target delay queue set from at least two preset delay queue sets according to a produced delay message task to receive the delay message task, so that information accumulation in each delay queue set is reduced, and an obvious reduction in message processing efficiency is avoided; moreover, the process matched with the target delay queue set is improved into a process set, so that single-point failure of the process is avoided; and because the processes are matched with the consumers, the message distribution and the task execution are separated, the processing efficiency is improved, and the expandability of the system is improved.
Referring now to FIG. 6, a block diagram of an electronic device (e.g., the server of FIG. 1) 600 suitable for implementing embodiments of the present application is shown. The terminal device in the embodiments of the present application may include, but is not limited to, a mobile terminal such as a mobile phone, a notebook computer, a digital broadcast receiver, a PDA (personal digital assistant), a PAD (tablet computer), a PMP (portable multimedia player), a vehicle terminal (e.g., a car navigation terminal), and the like, and a fixed terminal such as a digital TV, a desktop computer, and the like. The server shown in fig. 6 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present application.
As shown in fig. 6, electronic device 600 may include a processing means (e.g., central processing unit, graphics processor, etc.) 601 that may perform various appropriate actions and processes in accordance with a program stored in a Read Only Memory (ROM)602 or a program loaded from a storage means 608 into a Random Access Memory (RAM) 603. In the RAM603, various programs and data necessary for the operation of the electronic apparatus 600 are also stored. The processing device 601, the ROM 602, and the RAM603 are connected to each other via a bus 604. An input/output (I/O) interface 605 is also connected to bus 604.
Generally, the following devices may be connected to the I/O interface 605: input devices 606 including, for example, a touch screen, touch pad, keyboard, mouse, camera, microphone, accelerometer, gyroscope, etc.; an output device 607 including, for example, a Liquid Crystal Display (LCD), a speaker, a vibrator, and the like; storage 608 including, for example, tape, hard disk, etc.; and a communication device 609. The communication means 609 may allow the electronic device 600 to communicate with other devices wirelessly or by wire to exchange data. While fig. 6 illustrates an electronic device 600 having various means, it is to be understood that not all illustrated means are required to be implemented or provided. More or fewer devices may alternatively be implemented or provided. Each block shown in fig. 6 may represent one device or may represent multiple devices as desired.
In particular, according to embodiments of the application, the processes described above with reference to the flow diagrams may be implemented as computer software programs. For example, embodiments of the present application include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated by the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network via the communication means 609, or may be installed from the storage means 608, or may be installed from the ROM 602. The computer program, when executed by the processing device 601, performs the above-described functions defined in the methods of the embodiments of the present application.
It should be noted that the computer readable medium described in the embodiments of the present disclosure may be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In embodiments of the disclosure, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In embodiments of the present disclosure, however, a computer readable signal medium may comprise a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: electrical wires, optical cables, RF (Radio Frequency), etc., or any suitable combination of the foregoing.
The computer readable medium may be embodied in the server; or may exist separately and not be assembled into the server. The computer readable medium carries one or more programs which, when executed by the server, cause the server to: in response to receiving the delay message task, determining a delay queue set for receiving the delay message task as a target delay queue set, wherein the target delay queue set comprises a delay queue set which is selected from at least two preset delay queue sets and matched with the delay message task; selecting a target process from a process set matched with the target delay queue set; querying a delay message task to be processed in a target delay queue through a target process; and sending the delay message task to be processed to a preset message consumption queue.
Computer program code for carrying out operations for embodiments of the present disclosure may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C + +, and conventional procedural programming languages, such as "C", Python, or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the 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 the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units described in the embodiments of the present disclosure may be implemented by software or hardware. The described units may also be provided in a processor, and may be described as: a processor comprises a determining unit, a selecting unit, a querying unit and a sending unit. For example, the determining unit may be further described as "determining, in response to receiving the delayed message task, a set of delay queues receiving the delayed message task as a unit of a target set of delay queues, where the target set of delay queues includes a set of delay queues selected from at least two preset sets of delay queues and matched with the delayed message task".
The foregoing description is only exemplary of the preferred embodiments of the disclosure and is illustrative of the principles of the technology employed. It will be appreciated by those skilled in the art that the scope of the invention in the embodiments of the present disclosure is not limited to the specific combination of the above-mentioned features, but also encompasses other embodiments in which any combination of the above-mentioned features or their equivalents is made without departing from the inventive concept as defined above. For example, the above features and (but not limited to) technical features with similar functions disclosed in the embodiments of the present disclosure are mutually replaced to form the technical solution.

Claims (10)

1. A message processing method based on Redis comprises the following steps:
in response to receiving a delay message task, determining a delay queue set for receiving the delay message task as a target delay queue set, wherein the target delay queue set comprises a delay queue set which is selected from at least two preset delay queue sets and matched with the delay message task;
selecting a target process from the process set matched with the target delay queue set;
querying a delay message task to be processed in the target delay queue through the target process;
and sending the delay message task to be processed to a preset message consumption queue.
2. The method of claim 1, wherein the delayed message tasks in the set of delay queues correspond to delay time fractions characterizing delay processing time; and
the querying, by the target process, a pending deferred message task in the target deferred queue includes:
the following query steps are performed: selecting the smallest delay time fraction from the target delay queue set as a target fraction;
and in response to determining that the time indicated by the target score is not later than the time indicated by the current timestamp, determining the delayed message task corresponding to the target score as the to-be-processed delayed message task.
3. The method of claim 2, wherein said querying, by the target process, the target delay queue for pending delay message tasks further comprises:
and in response to determining that the time indicated by the target score is later than the time indicated by the current timestamp, continuing to perform the querying step after sleeping for a preset time.
4. The method according to one of claims 1 to 3, wherein the target process comprises a temporary node derived based on a Zookeeper election.
5. A Redis-based message processing apparatus comprising:
the device comprises a determining unit, a processing unit and a processing unit, wherein the determining unit is configured to respond to the received delay message task and determine a delay queue set for receiving the delay message task as a target delay queue set, and the target delay queue set comprises a delay queue set which is selected from at least two preset delay queue sets and matched with the delay message task;
a selecting unit configured to select a target process from a set of processes matching the set of target delay queues;
a query unit configured to query the target delay queue for pending delayed message tasks by the target process;
a sending unit configured to send the to-be-processed delayed message task to a preset message consumption queue.
6. A Redis-based message processing system, comprising:
the producer is configured to obtain information of at least two preset delay queue sets; selecting a target delay queue set from the at least two delay queue sets according to the information; storing the produced delay message tasks into the target delay queue set;
a message processing side configured to perform the method according to one of claims 1 to 4;
a consumer configured to select a delayed message task to be processed from the message consumption queue; and processing the selected to-be-processed delay message task.
7. The system of claim 6, wherein the at least two sets of delay queues comprise two sets of delay queues corresponding to a same key.
8. The system of claim 6 or 7, wherein the information of the at least two sets of delay queues comprises a key; and
the producer is further configured to:
determining hash values corresponding to keys of the at least two delay queue sets;
distributing the hash value corresponding to the key to a preset hash ring;
determining a hash value corresponding to the generated delayed message task in a manner consistent with the hash value corresponding to the generated key;
mapping a hash value corresponding to the delayed message task to the hash ring;
and selecting a target delay queue set according to the relative relation between the position of the hash value corresponding to the delay message task mapped to the hash ring and the position of the hash value corresponding to the key distributed to the preset hash ring.
9. A server, comprising:
one or more processors;
a storage device having one or more programs stored thereon;
when executed by the one or more processors, cause the one or more processors to implement the method of any one of claims 1-4.
10. A computer-readable medium, on which a computer program is stored which, when being executed by a processor, carries out the method according to any one of claims 1-4.
CN202110359735.3A 2021-04-02 2021-04-02 Redis-based message processing method, device, system, server and medium Pending CN114116247A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110359735.3A CN114116247A (en) 2021-04-02 2021-04-02 Redis-based message processing method, device, system, server and medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110359735.3A CN114116247A (en) 2021-04-02 2021-04-02 Redis-based message processing method, device, system, server and medium

Publications (1)

Publication Number Publication Date
CN114116247A true CN114116247A (en) 2022-03-01

Family

ID=80359232

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110359735.3A Pending CN114116247A (en) 2021-04-02 2021-04-02 Redis-based message processing method, device, system, server and medium

Country Status (1)

Country Link
CN (1) CN114116247A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115118768A (en) * 2022-06-27 2022-09-27 平安壹钱包电子商务有限公司 Task distribution method and device, storage medium and electronic equipment
CN117541356A (en) * 2023-12-04 2024-02-09 广州方舟信息科技有限公司 Order execution method, system, electronic equipment and storage medium

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115118768A (en) * 2022-06-27 2022-09-27 平安壹钱包电子商务有限公司 Task distribution method and device, storage medium and electronic equipment
CN117541356A (en) * 2023-12-04 2024-02-09 广州方舟信息科技有限公司 Order execution method, system, electronic equipment and storage medium

Similar Documents

Publication Publication Date Title
CN110781373B (en) List updating method and device, readable medium and electronic equipment
CN110619078B (en) Method and device for pushing information
CN111432001B (en) Method, apparatus, electronic device and computer readable medium for jumping scenes
CN111309747A (en) Data synchronization method, system and device
CN109992719B (en) Method and apparatus for determining push priority information
CN112379982A (en) Task processing method and device, electronic equipment and computer readable storage medium
CN113760488A (en) Method, device, equipment and computer readable medium for scheduling task
CN111309496A (en) Method, system, device, equipment and storage medium for realizing delay task
CN110852720A (en) Document processing method, device, equipment and storage medium
CN114116247A (en) Redis-based message processing method, device, system, server and medium
CN110519373B (en) Method and device for pushing information
CN111460020B (en) Method, device, electronic equipment and medium for resolving message
CN110619079B (en) Method and device for pushing information
CN110377654B (en) Data request processing method and device, electronic equipment and computer-readable storage medium
CN108811036B (en) Method and apparatus for displaying wireless access point information
CN113064704A (en) Task processing method and device, electronic equipment and computer readable medium
CN111597439A (en) Information processing method and device and electronic equipment
CN112115154A (en) Data processing and data query method, device, equipment and computer readable medium
CN116431523B (en) Test data management method, device, equipment and storage medium
CN111400322B (en) Method, apparatus, electronic device and medium for storing data
CN111294321B (en) Information processing method and device
CN111291254A (en) Information processing method and device
CN115348260B (en) Information processing method, device, equipment and medium based on campus information security
CN115994120B (en) Data file merging method, device, electronic equipment and computer readable medium
CN111625707B (en) Recommendation response method, device, medium and equipment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination