Method and system for improving execution efficiency of timing task by using redis
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- CHINA CITIC BANK CO LTD
- Filing Date
- 2022-12-05
- Publication Date
- 2026-05-05
AI Technical Summary
[0004]为解决现有技术的不足,本发明提出一种利用redis提高定时任务执行效率的方法及系统,拟解决现有技术中查询时间设置的不准确,存在交易无法按时处理或者轮空处理的技术问题
[0041] The method and system for improving the execution efficiency of scheduled tasks using Redis, as described in this invention, involves reading real-time transaction information, storing multiple real-time transaction records in a database table to obtain N records to be traded, setting a counting unit, updating the count based on transaction information, obtaining a preset timeout threshold for the corresponding transaction based on historical information, configuring the N records to be traded based on the preset timeout threshold, displaying a configuration success status when the configuration is complete, and then updating the count again based on transaction information until all N transaction records have been processed. By setting different preset timeout thresholds for different transaction information, differentiated scheduled transactions are achieved, resulting in a more versatile technical effect.
Smart Images

Figure CN115827738B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer-related technologies, specifically to a method and system for improving the execution efficiency of scheduled tasks using Redis. Background Technology
[0002] During software system implementation, sometimes a type of transaction is encountered: these transactions have complex processing logic, long processing times, and business rules require the system to process only one such transaction at a time. When the concurrency of such transactions is high, conventional synchronous processing methods may lead to a large number of transactions timeouts, resulting in a poor user experience.
[0003] A common asynchronous processing method is to use scheduled tasks to handle these transactions. Specifically, when a transaction arrives, its information is saved to the database, and the transaction ends. A scheduled task that actually processes the transaction runs continuously, periodically polling the database and retrieving the earliest N transaction records in chronological order for processing. Since the arrival time of a transaction is uncertain, the polling interval of the scheduled task must be estimated manually based on experience. Due to human error, the query time settings may be inaccurate, leading to technical problems such as transactions not being processed on time or being left unprocessed. Summary of the Invention
[0004] To address the shortcomings of existing technologies, this invention proposes a method and system for improving the execution efficiency of scheduled tasks using Redis. It aims to solve the technical problems in existing technologies, such as inaccurate query time settings, which result in transactions not being processed on time or being left unprocessed.
[0005] To achieve the above objectives, the technical solution adopted by the present invention includes:
[0006] The first aspect of this invention discloses a method for improving the execution efficiency of scheduled tasks using Redis. The method is applied to a system that uses Redis to improve the execution efficiency of scheduled tasks, the system being communicatively connected to a database table. The method includes:
[0007] Obtain first real-time transaction information;
[0008] The first real-time transaction information is input into the database table to generate N transaction records;
[0009] Based on the first real-time transaction information, the transaction counting unit is updated to obtain the first real-time count value;
[0010] By analyzing historical transaction information, a first preset timeout threshold is obtained;
[0011] Configure timeout limits for the Redis distributed lock according to the first preset timeout threshold, and obtain the first configuration state;
[0012] If the first configuration state is in a configuration success state, obtain the first read command;
[0013] The first real-time count value is read according to the first read instruction and judged to obtain the first count judgment result;
[0014] Based on the first counting judgment result, the N transaction records are obtained from the database table and processed one by one.
[0015] Furthermore, the method also includes:
[0016] Based on transaction characteristics, a transaction information preprocessing unit is constructed;
[0017] The first transaction information is input into the transaction information preprocessing unit for information preprocessing to obtain the second transaction information, wherein the second transaction information is the information required for transaction processing;
[0018] The second transaction information is stored as input information in the database table.
[0019] Furthermore, in the step of updating the count in the transaction counting unit according to the first counting instruction to obtain the first real-time count value, the count update is achieved by atomically incrementing the count in Redis using the INCR command, and each type of transaction corresponds to a count variable in Redis.
[0020] Furthermore, the method also includes:
[0021] By judging the transaction status of the N transaction records, a transaction status judgment result is obtained, which includes an unprocessed status and a processed status.
[0022] Transactions in an unprocessed state are recorded and processed one by one.
[0023] Furthermore, the process of recording and processing unprocessed transactions one by one involves arranging the unprocessed transaction records in chronological order of their insertion time and processing them one by one. After each transaction is processed, the transaction processing status is changed to "processed", and the transaction count in Redis is decremented by 1.
[0024] Furthermore, after obtaining the N transaction records from the database table based on the first counting judgment result and processing them one by one, the process ends by releasing the Redis distributed lock, thereby realizing the cyclic execution of the scheduled task.
[0025] Furthermore, the step of reading the first real-time count value according to the first read instruction and making a judgment to obtain the first count judgment result further includes:
[0026] Determine whether the first real-time count value is greater than the first natural number;
[0027] If the first real-time count value is less than or equal to the first natural number, the first execution process is obtained;
[0028] If the first real-time count value is greater than the first natural number, the second execution process is obtained;
[0029] Based on the first execution flow and the second execution flow, construct a counting judgment rule;
[0030] The first counting result is generated according to the counting judgment rule.
[0031] A second aspect of this invention discloses a system for improving the execution efficiency of scheduled tasks using Redis, comprising:
[0032] The acquisition module is used to acquire first real-time transaction information; input the first real-time transaction information into the database table to generate N transaction records; and update the count in the transaction counting unit according to the first real-time transaction information to obtain the first real-time count value.
[0033] The configuration module analyzes historical transaction information to obtain a first preset timeout threshold; it then configures timeout limits for the Redis distributed lock based on the first preset timeout threshold to obtain a first configuration state.
[0034] The judgment module, if the first configuration state is in the configuration success state, obtains a first read instruction; reads the first real-time count value according to the first read instruction and makes a judgment to obtain a first count judgment result;
[0035] The processing module is used to obtain the N transaction records from the database table based on the first counting judgment result and process them one by one.
[0036] A third aspect of the present invention discloses a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described method.
[0037] A fourth aspect of the present invention discloses an electronic device, including a processor and a memory;
[0038] The memory is used to store operation instructions;
[0039] The processor is configured to execute the above-described method by invoking the operation instructions.
[0040] The beneficial effects of this invention are as follows:
[0041] The method and system for improving the execution efficiency of scheduled tasks using Redis, as described in this invention, involves reading real-time transaction information, storing multiple real-time transaction records in a database table to obtain N records to be traded, setting a counting unit, updating the count based on transaction information, obtaining a preset timeout threshold for the corresponding transaction based on historical information, configuring the N records to be traded based on the preset timeout threshold, displaying a configuration success status when the configuration is complete, and then updating the count again based on transaction information until all N transaction records have been processed. By setting different preset timeout thresholds for different transaction information, differentiated scheduled transactions are achieved, resulting in a more versatile technical effect. Attached Figure Description
[0042] Figure 1 This is a schematic diagram of a method for improving the execution efficiency of scheduled tasks using Redis, provided in an embodiment of the present invention.
[0043] Figure 2 This is a schematic diagram of a system architecture for improving the execution efficiency of scheduled tasks using Redis, as provided in an embodiment of the present invention. Detailed Implementation
[0044] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.
[0045] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0046] The first aspect of this invention relates to a process as follows Figure 1The methods shown for improving the efficiency of scheduled task execution using Redis include:
[0047] Step S1: Obtain the first real-time transaction information;
[0048] Step S2: Input the first real-time transaction information into the database table to generate N transaction records;
[0049] Specifically, the first real-time transaction information refers to complex transaction information that needs to be processed at the current time. These transactions have complex processing logic and long processing times, and business rules require the system to process only one such transaction at a time. For example, in automotive supply chain finance, the group-mode loan disbursement, redemption, and warehouse transfer transactions have complex processing logic and long processing times. Furthermore, the data table refers to a database storing information awaiting transactions. Each received first real-time transaction information and the relevant information needed for the actual processing of the transaction are stored in the database table according to the order of receipt, resulting in N transaction records representing the information awaiting transactions at the current time. Each transaction corresponds to one database table record. For example, the business information required for transaction processing (group mode number, vehicle identification number, institution number, etc.), the current time (accurate to milliseconds), and the transaction status (initialized to "unprocessed") are stored in the group mode transaction access table. Each group corresponds to a unique group mode number. After storage, the table is in a response state for easy information retrieval in subsequent steps.
[0050] Step S3: Update the count in the transaction counting unit according to the first real-time transaction information to obtain the first real-time count value;
[0051] In this preferred embodiment, the count update is achieved by atomically incrementing the count in Redis using the INCR command, and each type of transaction corresponds to a count variable in Redis.
[0052] Specifically, the transaction counting unit refers to a module that counts transaction records in a database table and updates the transaction process. For example, the Redis module is used to count transaction status. Redis is an open-source key-value caching system with performance superior to databases, typically boasting single-machine concurrency of 100,000, enabling it to count transaction records. The counting method is as follows: the transaction counting unit is initialized to 0. Each time a transaction is received and stored in the database table, generating a transaction record, the count is atomically incremented by 1 using the `incr` command. Each type of transaction corresponds to a count variable in Redis. An example count format is: Group Mode Number_count. The first real-time count value is the count data obtained by updating the transaction counting unit in real time. This counting method is a complete process; if any step fails, the counting is displayed as a failure, thus ensuring the accuracy of the Redis count.
[0053] Step S4: Analyze historical transaction information to obtain a first preset timeout threshold;
[0054] Specifically, the historical transaction information refers to historical transactions of the same type as the first real-time transaction information, with each transaction record corresponding to multiple historical transaction information. The first preset timeout threshold is a time-sensitive threshold based on the historical transaction information to represent the transaction duration of the first real-time transaction information. By matching different transaction durations to different first real-time transaction information using the first preset timeout threshold, a reference basis is provided for further setting the query time interval for matching tasks, thus avoiding situations where transactions are not timely.
[0055] Step S5: Configure timeout limits for the Redis distributed lock according to the first preset timeout threshold to obtain the first configuration state;
[0056] Specifically, a first preset timeout threshold is used as the timeout limit for each first real-time transaction. This timeout limit is configured using a Redis distributed lock. When N transaction records are being configured, the Redis module displays the first configuration state. When configuration is complete, a configuration success status is displayed. For example, a Redis distributed lock is acquired, with the lock key being the group mode number. This ensures that the next transaction can only proceed after the previous transaction of N transaction records is completed, preventing situations where transactions are left unattended. Furthermore, if the subsequent transaction cannot proceed even after the first preset timeout threshold is exceeded, adjustments are needed. This prevents the Redis distributed lock from being unreleased in cases where the program executing the scheduled task exits abnormally or the server executing the scheduled task crashes.
[0057] Step S6: If the first configuration state is in the configuration success state, obtain the first read instruction;
[0058] Step S7: Read the first real-time count value according to the first read instruction and make a judgment to obtain the first count judgment result;
[0059] Specifically, when the first configuration state is in the configuration success state, it means that the first preset timeout thresholds corresponding to N transaction records have been configured. Then, the first read instruction is generated to read the real-time transaction status information and count value of N transaction records. First, the first real-time count value of the Redis counting unit is read, and it is determined whether the count is greater than 0. If it is not greater than 0, it means that there are no pending transactions, and the scheduled task is terminated directly. If it is greater than 0, it means that there are pending transactions. Then, the real-time transaction information of the current process is read through the first read instruction, and the transaction duration is recorded. The transaction duration is compared with the first preset timeout threshold. If the transaction duration is greater than the first preset timeout threshold, the relevant staff need to be notified to make adjustments. If the transaction duration is less than or equal to the first preset timeout threshold and the transaction is completed, the count in the transaction counting unit needs to be decremented by 1, and then the subsequent transactions in the N transaction records are executed. For example, the order of insertion time is recorded, and each transaction is processed one by one from first to last. After each transaction is processed, the transaction processing status is changed to "processed", and the transaction count in Redis is decremented by 1. The first counting judgment result is whether the count value is updated by -1. If it is updated, the next transaction processing is carried out; if it is not updated, the relevant staff are notified.
[0060] Step S8: Obtain the N transaction records from the database table based on the first counting judgment result and process them one by one.
[0061] Furthermore, step S8 also includes:
[0062] After obtaining the N transaction records from the database table based on the first counting result and processing them one by one, the process ends by releasing the Redis distributed lock, thus realizing the cyclic execution of the scheduled task.
[0063] Specifically, the system queries the N earliest stored records in the database. After each transaction is completed, if the first counting result indicates that the read count value is -1 and not 0, then the N transaction records are processed sequentially according to their storage order. After all records are processed, the Redis distributed lock is released, and the scheduled task is executed cyclically. This achieves the goal of ensuring that transactions are processed by the scheduled task as quickly as possible after they arrive, improving the counting efficiency and user experience.
[0064] Furthermore, the method also includes step S9, the specific method of which is as follows:
[0065] Based on transaction characteristics, a transaction information preprocessing unit is constructed;
[0066] The first transaction information is input into the transaction information preprocessing unit for information preprocessing to obtain the second transaction information, wherein the second transaction information is the information required for transaction processing;
[0067] The second transaction information is stored as input information in the database table.
[0068] Specifically, the transaction feature items are a set of transaction requirement information representing the information needed for processing transaction information; the transaction information preprocessing unit is a functional module that identifies the transaction feature items on the corresponding first transaction information; after receiving each transaction information, the transaction information preprocessing unit sets the transaction feature items corresponding to the transaction information as the second transaction information and stores them in the database table corresponding to the first transaction information. For example, in the automotive supply chain finance business, the loan disbursement, redemption, and warehouse transfer transactions in the group model are complex and time-consuming. When such transaction information is received, the business information required for transaction processing (group model number, vehicle identification number, institution number, etc.), the current time (accurate to milliseconds), and the transaction status (initialized to "unprocessed") are stored in the group model transaction access table. Each group corresponds to a unique group model number. By preprocessing the first transaction information, transaction processing requirement information is obtained, facilitating timely data retrieval during subsequent transactions and improving the real-time performance of transactions.
[0069] Furthermore, the method also includes step S10, the specific method of which is as follows:
[0070] By judging the transaction status of the N transaction records, a transaction status judgment result is obtained, which includes an unprocessed status and a processed status.
[0071] Record the M unprocessed transactions and process them one by one.
[0072] The process of recording and processing M unprocessed transactions involves arranging the M unprocessed transaction records in chronological order of their insertion time and processing them one by one. After processing each transaction, the transaction status is changed to "processed" and the transaction count in Redis is decremented by 1.
[0073] Specifically, the transaction status judgment result corresponds to the transaction information in N transaction records, and is divided into two states: unprocessed and processed, denoted as the first state and the second state, respectively. When the count value is not 0, the transaction status judgment result is read, and the M transaction records in the first state are processed step by step according to their storage order, where M is less than or equal to N. After processing, the transaction processing status is changed to "processed", and the transaction count in Redis is decremented by 1. For example, the earliest M records with the transaction status "unprocessed" in the group mode transaction access table are queried; each transaction is processed one by one in the order of its insertion time, and after each transaction is processed, the transaction processing status is changed to "processed", and the transaction count in Redis is decremented by 1. By reading the transaction status in real time to process the N transaction records, and identifying the transaction status to avoid the occurrence of empty runs, the next transaction can be started as soon as the previous transaction task is completed, improving the timeliness of transactions.
[0074] Furthermore, step S7 also includes:
[0075] S71: Determine whether the first real-time count value is greater than the first natural number;
[0076] S72: If the first real-time count value is less than or equal to the first natural number, obtain the first execution flow;
[0077] S73: If the first real-time count value is greater than the first natural number, the second execution process is obtained;
[0078] S74: Construct a counting judgment rule based on the first execution flow and the second execution flow;
[0079] S75: Generate the first counting judgment result according to the counting judgment rule.
[0080] Specifically, before executing a scheduled task transaction, a query is preferably performed every 3 seconds. The first natural number is a preset value indicating whether there are any pending transactions in the database table. For example, the first natural number is preset to 0. The first execution process means that when the first real-time count value read is less than or equal to 0, it means that there are no pending transactions in the database table, and the scheduled task is terminated directly. The second execution process means that when the first real-time count value read is greater than 0, it means that there are pending transactions in the database table, and the transaction status is read to process the pending transaction records in the database table step by step to avoid the system being idle and wasting resources.
[0081] In summary, the method for improving the execution efficiency of scheduled tasks using Redis provided in this application has the following technical effects:
[0082] 1. This application provides a method and system for improving the execution efficiency of scheduled tasks using Redis, solving the technical problem in the prior art where inaccurate query time settings lead to transactions not being processed on time or being left unprocessed. By reading real-time transaction information and storing multiple real-time transaction records in a database table, N records awaiting transaction are obtained. A counting unit is set, and the count is updated based on transaction information. A preset timeout threshold for the corresponding transaction is obtained based on historical information. The N records awaiting transaction are configured based on the preset timeout threshold. When configuration is complete, a successful configuration status is displayed. The count is then updated again based on transaction information until all N transaction records have been processed. Different preset timeout thresholds are set for different transaction information, achieving differentiated scheduled transactions and resulting in a more versatile technical effect.
[0083] 2. This application combines the Redis system with a database to implement a method for improving the execution efficiency of scheduled tasks using Redis. This allows transactions to be processed by scheduled tasks as quickly as possible after they arrive, improving the user experience; it also avoids empty database polling, saving valuable database connection resources; furthermore, by combining processing with the database, data integrity is ensured, and the problem of lost business data in Redis-based scheduled tasks is avoided.
[0084] Based on the same inventive concept as the method for improving the execution efficiency of scheduled tasks using Redis in the foregoing embodiments, such as Figure 2 As shown in the figure, this application embodiment provides a system for improving the execution efficiency of scheduled tasks using Redis, wherein the system includes:
[0085] The acquisition module is used to acquire first real-time transaction information; input the first real-time transaction information into the database table to generate N transaction records; and update the count in the transaction counting unit according to the first real-time transaction information to obtain the first real-time count value.
[0086] The configuration module analyzes historical transaction information to obtain a first preset timeout threshold; it then configures timeout limits for the Redis distributed lock based on the first preset timeout threshold to obtain a first configuration state.
[0087] The judgment module, if the first configuration state is in the configuration success state, obtains a first read instruction; reads the first real-time count value according to the first read instruction and makes a judgment to obtain a first count judgment result;
[0088] The processing module is used to obtain the N transaction records from the database table based on the first counting judgment result and process them one by one.
[0089] By using this system, the methods described above for improving the efficiency of scheduled tasks using Redis can be executed and the corresponding technical effects can be achieved.
[0090] Based on the same inventive concept as the method for improving the execution efficiency of scheduled tasks using Redis in the foregoing embodiments, embodiments of the present invention also provide a computer-readable storage medium capable of implementing all the steps of the method in the above embodiments, wherein a computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, it implements all the steps of the method in the above embodiments.
[0091] Based on the same inventive concept as the method for improving the execution efficiency of scheduled tasks using Redis in the foregoing embodiments, embodiments of the present invention also provide an electronic device for executing the above method. As an implementation device for the method, the electronic device has at least a processor and a memory. In particular, the memory stores the data and related computer programs required to execute the method, and the processor calls the data and programs in the memory to execute all the steps of the method and obtain the corresponding technical effect.
[0092] Preferably, the electronic device may include a bus architecture, which may include any number of interconnected buses and bridges. The bus will include various circuits linked together by one or more processors and memories. The bus may also link together various other circuits such as peripherals, voltage regulators, and power management circuits, which are well known in the art and therefore will not be described further herein. The bus interface provides an interface between the bus and the receiver and transmitter. The receiver and transmitter may be the same element, i.e., a transceiver, providing a unit for communicating with various other systems over a transmission medium. The processor is responsible for managing the bus and general processing, while the memory may be used to store data used by the processor during operation.
[0093] Additionally, the electronic device may further include components such as a communication module, an input unit, an audio processor, a display, and a power supply. The processor (or controller, operating control) used may include a microprocessor or other processor device and / or logic device, which receives input and controls the operation of various components of the electronic device; the memory may be one or more of a buffer, flash memory, hard drive, removable media, volatile memory, non-volatile memory, or other suitable devices, which can store the aforementioned data information, and may also store programs for executing the information, and the processor can execute the program stored in the memory to achieve information storage or processing, etc.; the input unit is used to provide input to the processor, for example, it can be a button or touch input device; the power supply is used to provide power to the electronic device; the display is used to display images and text, for example, it can be an LCD display. The communication module is a transmitter / receiver that transmits and receives signals via an antenna. The communication module (transmitter / receiver) is coupled to the processor to provide input signals and receive output signals, which can be the same as in conventional mobile communication terminals. Based on different communication technologies, multiple communication modules can be incorporated into the same electronic device, such as cellular network modules, Bluetooth modules, and / or wireless LAN modules. The communication module (transmitter / receiver) is also coupled to a speaker and microphone via an audio processor to provide audio output through the speaker and receive audio input from the microphone, thereby enabling typical telecommunications functions. The audio processor can include any suitable buffer, decoder, amplifier, etc. Furthermore, the audio processor is coupled to a central processing unit, enabling on-device recording via the microphone and on-device playback of stored sound via the speaker.
[0094] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0095] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A system that specifies functions in one or more boxes.
[0096] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including an instruction set implemented in a process. Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0097] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the functions specified in one or more boxes. Although preferred embodiments of the invention have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments as well as all changes and modifications falling within the scope of the invention.
[0098] The above description is merely a preferred embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A method for improving the execution efficiency of scheduled tasks using Redis, characterized in that, The method is applied to a system that utilizes Redis to improve the execution efficiency of scheduled tasks. The system communicates with a database table. The method includes: Obtain first real-time transaction information; The first real-time transaction information is input into the database table to generate N transaction records; Based on the first real-time transaction information, the transaction counting unit is updated to obtain the first real-time count value; By analyzing historical transaction information, a first preset timeout threshold is obtained; Configure timeout limits for the Redis distributed lock according to the first preset timeout threshold, and obtain the first configuration state; If the first configuration state is in a configuration success state, obtain the first read command; The first real-time count value is read according to the first read instruction and judged to obtain the first count judgment result; Based on the first counting judgment result, obtain the N transaction records from the database table and process them one by one; The step of reading the first real-time count value according to the first read instruction and making a judgment to obtain the first count judgment result includes: Determine whether the first real-time count value is greater than the first natural number; If the first real-time count value is less than or equal to the first natural number, the first execution process is obtained; If the first real-time count value is greater than the first natural number, the second execution process is obtained; Based on the first execution flow and the second execution flow, construct a counting judgment rule; The first counting result is generated according to the counting judgment rule.
2. The method as described in claim 1, characterized in that, The method further includes: Based on transaction characteristics, a transaction information preprocessing unit is constructed; The first transaction information is input into the transaction information preprocessing unit for information preprocessing to obtain the second transaction information, wherein the second transaction information is the information required for transaction processing; The second transaction information is stored as input information in the database table.
3. The method as described in claim 2, characterized in that, In the step of updating the count in the transaction counting unit based on the first real-time transaction information to obtain the first real-time count value, the count update is achieved by atomically incrementing the count in Redis using the INCR command, and each type of transaction corresponds to a count variable in Redis.
4. The method according to any one of claims 1 to 3, characterized in that, The method further includes: By judging the transaction status of the N transaction records, a transaction status judgment result is obtained, which includes an unprocessed status and a processed status. Transactions in an unprocessed state are recorded and processed one by one.
5. The method as described in claim 4, characterized in that, The process of recording and processing unprocessed transactions involves arranging the unprocessed transaction records in chronological order of their insertion time and processing them one by one. After each transaction is processed, the transaction status is changed to "processed" and the transaction count in Redis is decremented by 1.
6. The method as described in claim 5, characterized in that, After obtaining the N transaction records from the database table based on the first counting judgment result and processing them one by one, the process ends by releasing the Redis distributed lock, thus realizing the cyclic execution of the scheduled task.
7. A system for improving the execution efficiency of scheduled tasks using Redis, wherein the system communicates with a database table, characterized in that, include: The acquisition module is used to obtain first real-time transaction information; input the first real-time transaction information into the database table to generate N transaction records; Based on the first real-time transaction information, the transaction counting unit is updated to obtain the first real-time count value; The configuration module analyzes historical transaction information to obtain a first preset timeout threshold; it then configures timeout limits for the Redis distributed lock based on the first preset timeout threshold to obtain a first configuration state. The judgment module, if the first configuration state is in the configuration success state, obtains a first read instruction; reads the first real-time count value according to the first read instruction and makes a judgment to obtain a first count judgment result; The processing module is used to obtain the N transaction records from the database table based on the first counting judgment result and process them one by one; The step of reading the first real-time count value according to the first read instruction and making a judgment to obtain the first count judgment result includes: Determine whether the first real-time count value is greater than the first natural number; If the first real-time count value is less than or equal to the first natural number, the first execution process is obtained; If the first real-time count value is greater than the first natural number, the second execution process is obtained; Based on the first execution flow and the second execution flow, construct a counting judgment rule; The first counting result is generated according to the counting judgment rule.
8. A computer-readable storage medium, characterized in that, The storage medium stores a computer program, which, when executed by a processor, implements the method of any one of claims 1 to 6.
9. An electronic device, characterized in that, Including processor and memory; The memory is used to store operation instructions; The processor is configured to execute the method of any one of claims 1 to 6 by invoking the operation instructions.
Citation Information
Patent Citations
Current limiting method and device for transaction interface
CN107609976A
Asynchronous queuing processing method and system for payment transaction
CN114706872A