Search

CN-115827738-B - Method and system for improving execution efficiency of timing task by utilizing redis

CN115827738BCN 115827738 BCN115827738 BCN 115827738BCN-115827738-B

Abstract

The invention provides a method and a system for improving the execution efficiency of a timing task by utilizing redis, which relate to the technical field of computers, and the method comprises the steps of obtaining first real-time transaction information and inputting the first real-time transaction information into a database table to generate N transaction records; the method comprises the steps of carrying out counting update in a transaction counting unit according to first real-time transaction information to obtain a first real-time count value, carrying out overtime limiting configuration on a redis distributed lock by analyzing historical transaction information to obtain a first preset overtime threshold value to obtain a first configuration state, obtaining a first reading instruction to read the first real-time count value and judge if the first configuration state is in a successful configuration state, obtaining N transaction records from a database table by obtaining a first counting judgment result and carrying out one-by-one processing. The technical problem that in the prior art, the inquiry time is set inaccurately, so that the transaction cannot be processed on time or in the wheel space is solved.

Inventors

  • ZHU JIANG
  • LIU YONGSHENG
  • FANG JUN
  • YANG YANG
  • LIU YANJUN
  • ZHOU CHUO

Assignees

  • 中信银行股份有限公司

Dates

Publication Date
20260505
Application Date
20221205

Claims (9)

  1. 1. A method for improving efficiency of timed task execution using redis, the method being applied to a system for improving efficiency of timed task execution using redis, the system being communicatively coupled to a database table, the method comprising: obtaining first real-time transaction information; Inputting the first real-time transaction information into the database table to generate N transaction records; counting and updating in a transaction counting unit according to the first real-time transaction information to obtain a first real-time count value; analyzing the historical transaction information to obtain a first preset timeout threshold; performing timeout limiting configuration on the redis distributed lock according to the first preset timeout threshold to obtain a first configuration state; if the first configuration state is in a successful configuration state, a first reading instruction is obtained; Reading the first real-time count value according to the first reading instruction and judging to obtain a first count judgment result; obtaining the N transaction records from the database table according to the first counting judgment result and processing the transaction records one by one; the step of reading the first real-time count value according to the first reading instruction and judging, and the step of obtaining a first count judgment result comprises the following steps: judging whether the first real-time count value is larger than a first natural number or not; If the first real-time count value is smaller than or equal to the first natural number, a first execution flow is obtained; If the first real-time count value is larger than the first natural number, a second execution flow is obtained; Constructing a counting judgment rule according to the first execution flow and the second execution flow; and generating the first counting judgment result according to the counting judgment rule.
  2. 2. The method of claim 1, wherein the method further comprises: constructing a transaction information preprocessing unit according to the transaction characteristic item; Inputting the first transaction information into the transaction information preprocessing unit for information preprocessing to obtain second transaction information, wherein the second transaction information is information required by transaction processing; and storing the second transaction information as input information into the database table.
  3. 3. The method of claim 2, wherein the counting update is performed in a transaction counting unit according to the first real-time transaction information, wherein the counting update is performed by adding 1 to a count in the redis through an incr command atom, and each type of transaction corresponds to one counting variable in the redis.
  4. 4. A method according to any one of claims 1 to 3, wherein the method further comprises: The transaction state judgment result is obtained by judging the transaction states of the N transaction records, wherein the transaction state judgment result comprises an unprocessed state and a processed state; And recording the transactions in the unprocessed state and processing the transactions one by one.
  5. 5. The method of claim 4, wherein the recording and processing transactions in an unprocessed state one by one is performed by arranging transaction records in an unprocessed state in the order of the recording insertion time, and modifying the transaction processing state to "processed" and decreasing the transaction count in redis by 1 after each transaction is completed.
  6. 6. The method of claim 5, wherein the timing task loop execution is achieved by releasing the redis distributed lock to end after the N transaction records are obtained from the database table and processed one by one according to the first count determination result.
  7. 7. A system for improving efficiency of timed task execution using redis, said system in communication with a database table, comprising: the system comprises a database table, an acquisition module, a transaction counting unit, a counting module and a counting module, wherein the database table is used for storing the first real-time transaction information, the acquisition module is used for acquiring the first real-time transaction information, inputting the first real-time transaction information into the database table to generate N transaction records, and performing counting update in the transaction counting unit according to the first real-time transaction information to acquire a first real-time count value; the configuration module is used for carrying out overtime limiting configuration on the redis distributed lock according to the first preset overtime threshold value to obtain a first configuration state; The judging module is used for reading the first real-time count value according to the first reading instruction and judging to obtain a first count judging result; the processing module is used for obtaining the N transaction records from the database table according to the first counting judgment result and processing the N transaction records one by one; the step of reading the first real-time count value according to the first reading instruction and judging, and the step of obtaining a first count judgment result comprises the following steps: judging whether the first real-time count value is larger than a first natural number or not; If the first real-time count value is smaller than or equal to the first natural number, a first execution flow is obtained; If the first real-time count value is larger than the first natural number, a second execution flow is obtained; Constructing a counting judgment rule according to the first execution flow and the second execution flow; and generating the first counting judgment result according to the counting judgment rule.
  8. 8. A computer readable storage medium, characterized in that the storage medium has stored thereon a computer program which, when executed by a processor, implements the method of any of claims 1 to 6.
  9. 9. An electronic device comprising a processor and a memory; the memory is used for storing operation instructions; the processor is configured to execute the method of any one of claims 1 to 6 by invoking the operation instruction.

Description

Method and system for improving execution efficiency of timing task by utilizing redis Technical Field The invention relates to the technical field of computers, in particular to a method and a system for improving the execution efficiency of a timing task by utilizing redis. Background In the implementation process of a software system, a class of transactions is sometimes encountered, wherein the transaction processing logic is complex, the transaction processing time is long, and the business rule requires that the system can only process one transaction at the same time. When the concurrency of such transactions is large, conventional synchronous processing methods may cause a large number of transactions to timeout, and customer experience is poor. The common asynchronous processing method adopts a timing task to process the transaction, and specifically, when the transaction arrives, the transaction information is stored in a database, and the transaction is ended. A timing task for actually processing the transaction always runs, periodically polls the database, and takes out N transaction records with earliest time in time sequence for processing. Because it is uncertain when a transaction arrives at the system, the interval between timed task polls can only be estimated empirically by human. Because of the defect of manual operation, the inquiry time is set inaccurately, and the technical problem that the transaction cannot be processed on time or in the idle process exists. Disclosure of Invention In order to solve the defects of the prior art, the invention provides a method and a system for improving the execution efficiency of a timing task by utilizing redis, which aim to solve the technical problems that the inquiry time is set inaccurately and the transaction cannot be processed on time or in a wheel space. In order to achieve the above object, the present invention adopts the technical scheme that: The first aspect of the present invention discloses a method for improving execution efficiency of a timed task by using redis, the method is applied to a system for improving execution efficiency of a timed task by using redis, the system is in communication connection with a database table, the method comprises: obtaining first real-time transaction information; Inputting the first real-time transaction information into the database table to generate N transaction records; counting and updating in a transaction counting unit according to the first real-time transaction information to obtain a first real-time count value; analyzing the historical transaction information to obtain a first preset timeout threshold; performing timeout limiting configuration on the redis distributed lock according to the first preset timeout threshold to obtain a first configuration state; if the first configuration state is in a successful configuration state, a first reading instruction is obtained; Reading the first real-time count value according to the first reading instruction and judging to obtain a first count judgment result; And obtaining the N transaction records from the database table according to the first counting judgment result and processing the transaction records one by one. Further, the method further comprises: constructing a transaction information preprocessing unit according to the transaction characteristic item; Inputting the first transaction information into the transaction information preprocessing unit for information preprocessing to obtain second transaction information, wherein the second transaction information is information required by transaction processing; and storing the second transaction information as input information into the database table. Further, according to the first counting instruction, a counting update is performed in a transaction counting unit, and in the first real-time counting value obtained, the counting update is realized by adding 1 to the counting in the redis through an incr command atom, and each type of transaction corresponds to one counting variable in the redis. Further, the method further comprises: The transaction state judgment result is obtained by judging the transaction states of the N transaction records, wherein the transaction state judgment result comprises an unprocessed state and a processed state; And recording the transactions in the unprocessed state and processing the transactions one by one. Further, the recording and processing the transactions in the unprocessed state one by one is to arrange the transaction records in the unprocessed state one by one according to the sequence of the record insertion time, and after each transaction is completed, the transaction processing state is modified to be processed, and meanwhile, the transaction count in redis is reduced by 1. Further, after the N transaction records are obtained from the database table according to the first count judgment result and processed one by one, the redis di