Data processing method and related equipment

By utilizing the synchronization mechanism of Redis cache and database in high concurrency flash sale scenarios, the problem of database pressure and inventory oversold is solved, and the efficient and stable operation of the system and data integrity are achieved.

CN119621786AInactive Publication Date: 2025-03-14BEIJING HUAYI JINGDIAN BIOTECHNOLOGY CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202510163481.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-14
Publication Date
2025-03-14
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

In the case of high concurrency, the database needs to process a large number of read and write requests simultaneously, resulting in increased burden on the central processor and input/output, extended response time and even system crashes, which leads to the problem of page operation inter-stop, repeated orders, and oversold orders in the inventory of order goods.

Method used

By obtaining the inventory information of the products corresponding to the flash sale request from the Redis cache, performing checksum pre-deduction operations, and synchronizing the results to the database to ensure the consistency and accuracy of the inventory information. At the same time, setting constraint rules in the database to prevent negative inventory and ensure the integrity of the data.

Benefits of technology

It effectively reduces the pressure on the database, avoids the risk of oversold goods, ensures the uniqueness of orders, improves the system's response speed, and maintains the consistency and integrity of data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119621786A_ABST
    Figure CN119621786A_ABST
Patent Text Reader

Abstract

The invention provides a data processing method and related equipment. The method comprises the following steps: in response to a seckilling request event of a user, obtaining first inventory information of a commodity corresponding to a seckilling request from a Redis cache; inventory information of all commodities is loaded in the Redis cache in advance; verifying the first inventory information to obtain a first verification result, and performing a first operation on the first inventory information based on the first verification result; and synchronizing a result of the first operation to a database, verifying second inventory information of the corresponding commodity in the database to obtain a second verification result, and returning a seckilling result to the user based on the second verification result. According to the embodiment of the invention, the inventory information is placed in the Redis cache, and the secondary synchronization of the inventory information is carried out in the database, so that the problem of page jamming caused by repeated oversell of system orders due to seckilling activity is effectively solved, and unnecessary economic loss of a company is avoided.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of inventory data management, and in particular to a data processing method and related equipment. Background Art

[0002] When users place orders, they directly access the database through server applications. When a large number of users or applications send requests to the database at the same time, the database needs to handle a large number of read and write requests at the same time, which increases the burden on the central processor and input / output, resulting in longer response time and even system crashes. This leads to problems such as page operation interaction jams, duplicate orders, and oversold inventory of ordered items. This in turn causes trouble for the company's warehouse and finance. Summary of the invention

[0003] In view of this, the purpose of this application is to provide a data processing method and related equipment.

[0004] Based on the above purpose, the present application provides a data processing method, including: In response to a flash sale request event from a user, first inventory information of a product corresponding to the flash sale request is obtained from a Redis cache; the Redis cache is pre-loaded with inventory information of all products; Verifying the first inventory information to obtain a first verification result, and performing a first operation on the first inventory information based on the first verification result; The result of the first operation is synchronized to a database, and the second inventory information of the corresponding product is verified in the database to obtain a second verification result, and a flash sale result is returned to the user based on the second verification result.

[0005] In a possible implementation manner, verifying the first inventory information to obtain a first verification result, and performing a first operation on the first inventory information based on the first verification result includes: Get the quantity of products corresponding to the flash sale request; comparing the commodity quantity with the first inventory information, and in response to the first inventory information being greater than the commodity quantity, performing a pre-deduction operation on the first inventory information; In response to the first inventory information being less than the commodity quantity, the first inventory information is kept unchanged, and a user is prompted that the inventory is insufficient.

[0006] In a possible implementation, synchronizing the result of the first operation to a database includes: Sending the result of the first operation to a database; The second inventory is synchronously processed based on the result of the first operation by using a database query statement.

[0007] In a possible implementation, verifying the second inventory information of the corresponding product in the database to obtain a second verification result, and returning a flash sale result to the user based on the second verification result includes: Determining whether the second verification result after the synchronous deduction process is greater than or equal to zero; In response to the second verification result being greater than or equal to zero, the first operation result is synchronized to the transaction success in the database, and a purchase success result is returned to the user; In response to the second verification result being less than zero, the transaction in which the first operation result is synchronized to the database fails, the transaction is rolled back, and a user is prompted that the inventory is insufficient.

[0008] In a possible implementation, the method further includes: adding a first constraint in the database; the first constraint is to restrict the inventory information in the database to not be a negative number; After the first operation result is successfully synchronized to the transaction in the database, the method further includes: Determining whether a field of the second inventory information in the database satisfies a first constraint; In response to the field of the second inventory information not satisfying the first constraint, the transaction is rolled back, and a user is prompted that the inventory is insufficient.

[0009] In a possible implementation, after synchronizing the result of the first operation to the database, the method further includes: Verify the order number corresponding to the flash sale request; In response to the order number being unique, continuing the inventory verification operation; In response to the order number being not unique, a request error message is returned to the user.

[0010] Based on the same inventive concept, the embodiment of the present application further provides a data processing device, including: The acquisition module is configured to, in response to a flash sale request event of a user, acquire first inventory information of a product corresponding to the flash sale request from a Redis cache; the Redis cache is pre-loaded with inventory information of all products; a verification module, configured to verify the first inventory information, obtain a first verification result, and perform a first operation on the first inventory information based on the first verification result; The return module is configured to synchronize the result of the first operation to the database, verify the second inventory information of the corresponding product in the database, obtain a second verification result, and return the flash sale result to the user based on the second verification result.

[0011] Based on the same inventive concept, an embodiment of the present application also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the data processing method as described in any one of the above is implemented.

[0012] Based on the same inventive concept, an embodiment of the present application further provides a non-transitory computer-readable storage medium, wherein the non-transitory computer-readable storage medium stores computer instructions, and the computer instructions are used to enable the computer to execute any of the above-mentioned data processing methods.

[0013] Based on the same inventive concept, an embodiment of the present application further provides a computer program product, which includes computer program instructions, and the computer instructions are used to enable the computer program product to execute any of the above-mentioned data processing methods.

[0014] As can be seen from the above, the data processing method and related equipment provided by the present application, in response to the user's flash sale request event, obtain the first inventory information of the product corresponding to the flash sale request from the Redis cache; the Redis cache is pre-loaded with the inventory information of all products; the first inventory information is verified to obtain a first verification result, and based on the first verification result, a first operation is performed on the first inventory information; the result of the first operation is synchronized to the database, and the second inventory information of the corresponding product is verified in the database to obtain a second verification result, and the flash sale result is returned to the user based on the second verification result. The embodiment of the present application effectively reduces the pressure on the database by loading the inventory information of the product into the Redis cache, and then effectively avoids the risk of overselling of the product through resynchronization in the database and corresponding field constraints. Furthermore, the corresponding order uniqueness detection related means are also set in the database, which effectively guarantees the uniqueness of the order and avoids troubles for the user's use, and introduces a message queue, and effectively improves the response speed of the system through asynchronous operation. Through the above technical solution, it can effectively ensure efficient and stable operation in high-concurrency flash sale scenarios, while maintaining data consistency and integrity. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] In order to more clearly illustrate the technical solutions in the present application or related technologies, the drawings required for use in the embodiments or related technical descriptions are briefly introduced below. Obviously, the drawings described below are only embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0016] Figure 1 A schematic diagram of a data processing method flow chart of an embodiment of the present application; Figure 2 This is a schematic diagram of the overall process of an embodiment of the present application; Figure 3 This is a schematic diagram of the peak period of flash sales in an embodiment of the present application; Figure 4 This is a schematic diagram of the structure of a data processing device according to an embodiment of the present application; Figure 5 This is a schematic diagram of the structure of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION

[0017] In order to make the objectives, technical solutions and advantages of the present application more clearly understood, the present application is further described in detail below in combination with specific embodiments and with reference to the accompanying drawings.

[0018] It should be noted that, unless otherwise defined, the technical terms or scientific terms used in the embodiments of the present application should be the usual meanings understood by people with ordinary skills in the field to which the present application belongs. The "first", "second" and similar words used in the embodiments of the present application do not represent any order, quantity or importance, but are only used to distinguish different components. "Including" or "comprising" and similar words mean that the elements or objects appearing in front of the word cover the elements or objects listed after the word and their equivalents, without excluding other elements or objects. "Connect" or "connected" and similar words are not limited to physical or mechanical connections, but can include electrical connections, whether direct or indirect. "Up", "down", "left", "right" and the like are only used to indicate relative positional relationships. When the absolute position of the described object changes, the relative positional relationship may also change accordingly.

[0019] It is understandable that before using the technical solutions of each embodiment of the present disclosure, the type, scope of use, usage scenarios, etc. of the personal information involved will be informed to the user in an appropriate manner, and the user's authorization will be obtained.

[0020] For example, in response to receiving an active request from a user, a prompt message is sent to the user to clearly remind the user that the operation requested to be performed will require obtaining and using the user's personal information. Thus, the user can independently choose whether to provide personal information to software or hardware such as an electronic device, application, server, or storage medium that performs the operation of the technical solution of the present disclosure according to the prompt message.

[0021] As an optional but non-limiting implementation, in response to receiving the user's active request, the prompt information may be sent to the user in the form of a pop-up window, in which the prompt information may be presented in text form. In addition, the pop-up window may also carry a selection control for the user to choose "agree" or "disagree" to provide personal information to the electronic device.

[0022] It is understandable that the above notification and the process of obtaining user authorization are merely illustrative and do not constitute a limitation on the implementation of the present disclosure. Other methods that meet relevant laws and regulations may also be applied to the implementation of the present disclosure.

[0023] As mentioned in the background technology section, when users place orders, they directly access the database through the server application. When a large number of users or applications send requests to the database at the same time, the database needs to process a large number of read and write requests at the same time, which increases the burden on the central processing unit and input / output, resulting in longer response time and even system crashes. This leads to problems such as page operation interaction jams, duplicate orders, and oversold inventory of ordered goods. This in turn causes trouble for the company's warehouse and finance.

[0024] Based on the above considerations, the embodiment of the present application proposes a data processing method, in response to the user's flash sale request event, obtaining the first inventory information of the product corresponding to the flash sale request from the Redis cache; the Redis cache is pre-loaded with the inventory information of all products; the first inventory information is verified to obtain a first verification result, and based on the first verification result, a first operation is performed on the first inventory information; the result of the first operation is synchronized to the database, and the second inventory information of the corresponding product is verified in the database to obtain a second verification result, and the flash sale result is returned to the user based on the second verification result. The embodiment of the present application effectively reduces the pressure on the database by loading the inventory information of the product into the Redis cache, and then effectively avoids the risk of overselling of the product through resynchronization in the database and corresponding field constraints. Furthermore, the corresponding order uniqueness detection related means are also set in the database, which effectively guarantees the uniqueness of the order and avoids troubles for the user's use, and introduces a message queue, and effectively improves the response speed of the system through asynchronous operation. Through the above technical solution, it can effectively ensure efficient and stable operation in high-concurrency flash sale scenarios, while maintaining data consistency and integrity.

[0025] The technical solutions of the embodiments of the present application are described in detail below through specific examples.

[0026] refer to Figure 1 The data processing method of the embodiment of the present application comprises the following steps: Step S101, in response to a flash sale request event from a user, obtaining first inventory information of a product corresponding to the flash sale request from a Redis cache; the Redis cache is pre-loaded with inventory information of all products; Step S102, verifying the first inventory information to obtain a first verification result, and performing a first operation on the first inventory information based on the first verification result; Step S103, synchronizing the result of the first operation to the database, verifying the second inventory information of the corresponding product in the database to obtain a second verification result, and returning the flash sale result to the user based on the second verification result.

[0027] refer to Figure 2 , which is a schematic diagram of the overall process of the embodiment of the present application.

[0028] The following combination Figure 1 and Figure 2 The embodiment of the present application is described in detail. For step S101, first, it is necessary to use Redis (redis) technology cache to store product information in the cache in advance. When placing an order, obtain the product in the cache through redis.HashGet, verify the inventory quantity, and update the inventory quantity of the product in the cache through redis.HashSet after the order is successfully placed.

[0029] Specifically, before the flash sale begins, key product information (such as inventory quantity, price, etc.) is stored in the Redis cache in advance so that it can be quickly read under high concurrency conditions, avoiding performance bottlenecks caused by frequent access to the database.

[0030] In this embodiment, the administrator can configure the product information (including product ID, inventory quantity, price, etc.) in advance and store it in the hash structure of Redis. The hash structure (Hash) allows multiple fields and values ​​to be stored under one key in Redis, which is very suitable for storing structured data such as product information. Each product uses the product ID as the primary key, and the product's inventory quantity, price and other information are stored as hash fields. For example, the product ID is 1001, the inventory is 50, and the price is 100 yuan. Redis's hash structure allows for fast reading and updating of inventory fields while ensuring the structuring of data.

[0031] Redis in the embodiment of the present application is a memory-based NoSQL database with extremely fast reading speed, which can greatly improve the system's access speed to inventory information. In addition, if the inventory and other information of the goods are centrally stored in Redis, it is convenient for unified management and operation, and the vast majority of direct access requests to the database can be filtered out through caching, avoiding database overload due to high concurrency.

[0032] Furthermore, after the flash sale begins, when a user initiates a flash sale request, the system can first read the inventory information from the Redis cache instead of directly accessing the database. This approach can significantly increase processing speed and reduce database pressure.

[0033] Specifically, in a feasible embodiment, the steps may be that the user clicks a flash sale button, and the backend receives the flash sale request. The backend logic obtains the first inventory information of the corresponding product from the Redis hash structure according to the product ID submitted by the user.

[0034] Further, with respect to step S102, the first inventory information is verified to obtain a first verification result, and based on the first verification result, a first operation is performed on the first inventory information.

[0035] In some embodiments, the first inventory information is verified to obtain a first verification result, and based on the first verification result, a first operation is performed on the first inventory information, including: obtaining the quantity of goods corresponding to the flash sale request; comparing the quantity of goods with the first inventory information, and in response to the first inventory information being greater than the quantity of goods, performing a pre-deduction operation on the first inventory information; in response to the first inventory information being less than the quantity of goods, keeping the first inventory information unchanged and prompting the user that the inventory is insufficient.

[0036] In this embodiment, if the first inventory information is 0, a prompt "the product is sold out" is directly returned, and the flash sale ends. If the first inventory information is greater than 0, the subsequent flash sale logic continues.

[0037] For example, the administrator pre-sets a product in the background (product ID: 1001), with an initial inventory of 50 and a price of 100 yuan.

[0038] Product information is loaded into the Redis cache. The Redis hash structure is as follows: Key: product:1001.

[0039] Fields: Stock: 50; Price: 100.

[0040] The flash sale event starts, and user C initiates a flash sale request: The system reads the inventory quantity of product 1001 from the Redis cache and finds that the current inventory is 50. The system checks whether the inventory is sufficient. If the inventory is greater than 0, user C is allowed to continue the flash sale. The system uses the Redis decrement operation to reduce the product inventory from 50 to 49. User C's flash sale is successful, and the system returns a prompt indicating that the flash sale is successful.

[0041] refer to Figure 3 , which is a schematic diagram of the peak period of flash sales in an embodiment of the present application.

[0042] like Figure 3As shown in the figure, during the peak of flash sales, user A and user B simultaneously initiate flash sales requests, and the current inventory of product 1001 in Redis is 1. User A and user B read the inventory value of Redis almost at the same time. Redis ensures that the inventory deduction process is serial through atomic decrement operations: user B's request is executed first, and the inventory is reduced from 1 to 0. User A's request is executed later, and the inventory is already 0 at this time, which means that the inventory is insufficient. The inventory information is less than the requested number of products, and the database field cannot be negative. In the end, user B's flash sales are successful, and the system returns a prompt that the flash sales are successful. User A's flash sales fail, and the prompt that the product is sold out is displayed.

[0043] The quantity of goods requested by the aforementioned users A, B, and C is all 1. In other embodiments, other quantities may be requested, which is only for the convenience of explanation.

[0044] Further, with respect to step S103, synchronizing the result of the first operation to the database includes: sending the result of the first operation to the database; and synchronizing the second inventory based on the result of the first operation by using a database query statement.

[0045] In some embodiments, the second inventory information of the corresponding product is verified in the database to obtain a second verification result, and the flash sale result is returned to the user based on the second verification result, including: determining whether the second verification result after the synchronous deduction processing is greater than or equal to zero; in response to the second verification result being greater than or equal to zero, the transaction in which the first operation result is synchronized to the database is successful, and a successful purchase result is returned to the user; in response to the second verification result being less than zero, the transaction in which the first operation result is synchronized to the database fails, the transaction is rolled back, and the user is prompted that the inventory is insufficient.

[0046] In order to avoid overselling problems in the flash sale scenario, the above technical solution of this application can accurately control the inventory through transactions and Structured Query Language (SQL) statements at the database level. In this solution, inventory deduction is achieved through SQL statements, and the transaction mechanism is used to verify the operation. Once the result of the inventory deduction is negative, the system will automatically roll back the transaction to ensure data consistency. The following is a detailed description of the entire technical solution.

[0047] A database transaction is a mechanism that ensures that a set of operations either all succeed or all fail. Transactions can ensure that inventory deduction operations have the following characteristics: Atomicity: Once an inventory deduction fails or an error occurs, the entire deduction operation will be rolled back to avoid erroneous updates.

[0048] Consistency: Ensure that the inventory always remains in a consistent state, and there will be no situation where some data is updated and some is not updated during the deduction process.

[0049] Isolation: When multiple users operate on the inventory at the same time, transaction isolation can avoid concurrent reading and writing problems.

[0050] Durability: Once a transaction is committed, data updates are permanently written to the database.

[0051] In the database table, the inventory information of each product is stored in a field (such as the stock field). When a user initiates a purchase request, the system will query the current inventory data based on the unique primary key (product ID) of the product.

[0052] The first operation refers to the result (such as the updated inventory quantity) generated after the SQL statement for deducting inventory is executed. This result needs to be synchronized to the database to ensure the accuracy and real-time nature of the inventory information. First, the database will receive an operation request to deduct inventory. Based on the flash sale product ID and quantity information passed by the user, the database executes the SQL statement for deducting inventory and returns the second verification result after deduction. The second verification result is then judged. If it is greater than or equal to zero, the transaction in the database where the first operation result is synchronized successfully, and the result of the successful purchase is returned to the user. If it is less than zero, the transaction in the database where the first operation result is synchronized failed, the transaction is rolled back, and the user is prompted that the inventory is insufficient.

[0053] If the second inventory information data is greater than or equal to zero, the system will update the inventory and return the result of the flash sale to the user. If the second inventory data cannot meet the user's request, the system will perform a transaction rollback operation and return a prompt message of insufficient inventory to the user.

[0054] The operation of deducting inventory is completed through SQL statements. The specific implementation method is as follows: Use the database transaction mechanism to ensure that the key operation of deducting inventory is atomic, that is, the operation is either completely successful or completely failed. Perform the inventory deduction operation in the SQL query and return the updated inventory value at the same time. If the result of the inventory deduction is less than zero, the system will detect this abnormal situation and trigger a transaction rollback. The updated inventory quantity is returned to the application layer through OUTPUT or other technologies (such as stored procedures) in the SQL statement. This return value is used to verify the legitimacy of the inventory and determine whether the purchase request can continue to be processed.

[0055] After the inventory deduction operation is completed, the system will judge the deduction result. If the returned inventory quantity is less than zero, it means that the current inventory is insufficient to meet the user's request.

[0056] When the inventory is insufficient, the system will trigger a transaction rollback mechanism. Transaction rollback can undo the previous inventory deduction operation and restore the inventory data of the product. The transaction isolation level of the database can ensure that other concurrent requests cannot read incorrect data before the transaction is completed. If the inventory deduction fails and triggers a transaction rollback, the system will return a prompt message to the user saying "Product sold out" or "Insufficient inventory".

[0057] Finally, users who successfully purchase the flash sale will receive a prompt message saying “The flash sale was successful, please pay.” Users who fail the flash sale will receive a prompt message saying “The product is sold out” or “Insufficient stock.”

[0058] In some embodiments, the method further includes: adding a first constraint to the database; the first constraint is to limit the inventory information in the database to not be a negative number; after the transaction in which the first operation result is synchronized to the database successfully, the method further includes determining whether the field of the second inventory information in the database satisfies the first constraint; in response to the field of the second inventory information not satisfying the first constraint, executing a transaction rollback, and prompting a user that the inventory is insufficient.

[0059] In this embodiment, in a high-concurrency flash sale scenario, in order to further prevent the system from overselling due to logic loopholes, unexpected concurrency problems, or synchronization delays between the cache and the database, a constraint rule (first constraint) can be added at the database level to restrict the value of the inventory field to never be negative. This constraint ensures the security and consistency of inventory operations through the mechanism of the database itself, and is a bottom-level protection strategy.

[0060] The first constraint is an integrity constraint at the database level, which ensures that the inventory field of a product is always greater than or equal to zero. This constraint automatically takes effect when any SQL operation involving inventory deduction is executed. If the deducted inventory value is less than zero, the database will directly refuse to execute the operation and throw an exception.

[0061] Database constraints can be implemented in several ways: Check Constraint: When creating or modifying a table structure, add a check rule that limits the value of the inventory field to be greater than or equal to zero.

[0062] Trigger: When performing operations such as INSERT and UPDATE, the trigger is used to check whether the value of the inventory field meets the conditions. If not, the operation is rejected.

[0063] By using constraints directly at the database level, prevent inventory values ​​from entering illegal states (such as negative numbers).

[0064] When multiple users initiate flash sale requests at the same time, that is, a high concurrency scenario, the inventory may not be enough to meet the common number of requests from multiple users. If the first constraint is not set to constrain the underlying logic of the database field when the aforementioned Redis cache inventory is successfully deducted and the database synchronization transaction is successful, overselling will occur. Therefore, in order to prevent such situations from happening, this application also sets an additional line of defense of the first constraint after the database synchronization transaction is completed. In database transactions, the first constraint will be used as part of the constraint check. After the database synchronization transaction is successful, if the field in the database violates the first constraint, the transaction will automatically roll back to ensure data consistency. This design can prevent overselling due to unexpected concurrency problems or logical loopholes.

[0065] It can be seen that, whether it is a high-concurrency scenario or a logical vulnerability, this underlying constraint ensures the legitimacy of the inventory data and avoids vulnerabilities caused by insufficient processing at the system level. Even if there is a delay or failure in the synchronization between the cache layer (Redis) and the database, or the logical judgment of the aforementioned Redis cache and the database level is broken due to high concurrency, there will be no negative inventory in the database. The first constraint implements the constraint logic at the bottom of the database, and there is no need to repeat the inventory legitimacy verification at the application layer, thereby simplifying the development process. Even if the developer forgets to handle the inventory verification in the code, the database will automatically provide protection during execution. In addition, the constraint mechanism of the database is mandatory and cannot be bypassed. Even if there are vulnerabilities or logical errors in the code, the limitations of the database cannot be broken. Even in extreme cases (such as high concurrency, system crashes, and network interruptions), the inventory data can still be guaranteed not to be negative. When a constraint violation occurs, the database will throw a clear error message, which is convenient for the development team to quickly locate the problem. The error message contains the illegal value of the inventory field and the source of the operation, which is convenient for subsequent exception handling.

[0066] In some embodiments, after synchronizing the result of the first operation to the database, the method further includes: verifying the order number corresponding to the flash sale request; in response to the order number being unique, continuing the inventory verification operation; in response to the order number not being unique, returning a request error message to the user.

[0067] In this embodiment, in a high-concurrency flash sale scenario, in order to ensure the accuracy of the system's order processing logic and the consistency of inventory operations, the order number of the flash sale request must be verified. Order number uniqueness verification is an important part of ensuring the robustness of the flash sale system. It can effectively prevent duplicate order problems caused by repeated requests, malicious attacks, or network jitter. By verifying the uniqueness of the order number, problems such as repeated inventory deductions and creation of duplicate orders can be avoided, and the accuracy of subsequent inventory data and order data can be guaranteed.

[0068] In the flash sale system, each user's flash sale request will generate a unique order number to identify the request. The order number is usually generated by the system according to certain rules and can contain the following information: Timestamp: used to identify the creation time of the order and ensure the order number is sequential.

[0069] User ID: The user to whom the order belongs.

[0070] Product ID: Identifies the product information of an order.

[0071] Random number or hash value: used to enhance the uniqueness of the order number and avoid conflicts caused by duplication of time and user ID.

[0072] Order number verification is usually performed before inventory verification operations to ensure that only unique order numbers can continue with inventory verification and deduction operations. If the order number is not unique, the system will immediately reject the request and return a clear error message to the user to avoid continuing to occupy resources for subsequent operations.

[0073] Specifically, when a user initiates a flash sale request, the system generates an order number according to the preset rules and binds the order number to the relevant information of the request (such as user ID, product ID, and request time). The rules for generating order numbers need to ensure uniqueness in high-concurrency scenarios to avoid duplicate order numbers due to timestamp conflicts or duplicate user IDs. Each time an order number is generated, the system checks in the storage whether the order number already exists. If the order number does not exist, it is considered unique, and the system records the order number in the storage and continues the inventory verification operation.

[0074] If the order number already exists, the request is considered a duplicate or malicious request, and the system will directly reject the operation and return a "request error" or "duplicate order" prompt message to the user.

[0075] In high-concurrency scenarios, there may be multiple requests generating the same order number within a short period of time (for example, timestamp conflicts with random numbers).

[0076] The system can handle order number conflicts through the following mechanisms: Optimistic locking mechanism: When writing the order number to storage, the atomic operation capability of the storage system (such as Redis's SETNX) is used to ensure that the order number written is unique and cannot be overwritten.

[0077] Retry mechanism: If an order number conflict is detected, the system can regenerate the order number until a unique order number is generated.

[0078] If the order number verification passes, the system will continue to perform inventory verification: check whether the inventory of the product is sufficient to meet the user's purchase needs. If the inventory is sufficient, the inventory is deducted and the order is generated. If the inventory is insufficient or the order number verification fails, the request is directly rejected.

[0079] If the order number verification fails, the system will immediately reject the request and return an error message. The system can also record the abnormal request for subsequent analysis to determine whether it is a normal user's misoperation or a malicious attack.

[0080] The above embodiment can avoid inventory deduction errors and resource waste caused by duplicate orders by introducing order number uniqueness verification. Order number verification is a prerequisite for inventory verification and effectively intercepts abnormal requests. Even in high concurrency and malicious request scenarios, the system can still run stably. Clear error prompts are returned to reduce user waiting time.

[0081] It can be seen from the above embodiments that the data processing method described in the embodiment of the present application, in response to the user's flash sale request event, obtains the first inventory information of the product corresponding to the flash sale request from the Redis cache; the Redis cache is pre-loaded with the inventory information of all products; the first inventory information is verified to obtain a first verification result, and based on the first verification result, a first operation is performed on the first inventory information; the result of the first operation is synchronized to the database, and the second inventory information of the corresponding product is verified in the database to obtain a second verification result, and the flash sale result is returned to the user based on the second verification result. The embodiment of the present application effectively reduces the pressure on the database by loading the inventory information of the product into the Redis cache, and then effectively avoids the risk of overselling of the product through resynchronization in the database and corresponding field constraints. Furthermore, the corresponding order uniqueness detection related means are also set in the database, which effectively guarantees the uniqueness of the order and avoids troubles for the user's use, and introduces a message queue, and effectively improves the response speed of the system through asynchronous operation. Through the above technical solution, it can effectively ensure efficient and stable operation in high-concurrency flash sale scenarios, while maintaining data consistency and integrity.

[0082] It should be noted that the method of the embodiment of the present application can be performed by a single device, such as a computer or server. The method of this embodiment can also be applied to a distributed scenario and completed by multiple devices cooperating with each other. In the case of such a distributed scenario, one of the multiple devices can only perform one or more steps in the method of the embodiment of the present application, and the multiple devices will interact with each other to complete the described method.

[0083] It should be noted that the above describes some embodiments of the present application. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the above embodiments and still achieve the desired results. In addition, the processes depicted in the accompanying drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0084] Based on the same inventive concept, corresponding to any of the above-mentioned embodiment methods, the present application also provides a data processing device.

[0085] refer to Figure 4 , the data processing device comprises: The acquisition module 41 is configured to, in response to a flash sale request event of a user, acquire first inventory information of a product corresponding to the flash sale request from a Redis cache; the Redis cache is pre-loaded with inventory information of all products; A verification module 42 is configured to verify the first inventory information, obtain a first verification result, and perform a first operation on the first inventory information based on the first verification result; The return module 43 is configured to synchronize the result of the first operation to the database, verify the second inventory information of the corresponding product in the database, obtain a second verification result, and return the flash sale result to the user based on the second verification result.

[0086] For the convenience of description, the above device is described in terms of functions divided into various modules. Of course, when implementing the present application, the functions of each module can be implemented in the same or multiple software and / or hardware.

[0087] The device of the above embodiment is used to implement the corresponding data processing method in any of the above embodiments, and has the beneficial effects of the corresponding method embodiment, which will not be described in detail here.

[0088] Based on the same inventive concept, corresponding to any of the above-mentioned embodiments and methods, the present application also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the data processing method described in any of the above embodiments is implemented.

[0089] Figure 5A more specific schematic diagram of the hardware structure of an electronic device provided in this embodiment is shown, and the device may include: a processor 1010, a memory 1020, an input / output interface 1030, a communication interface 1040, and a bus 1050. The processor 1010, the memory 1020, the input / output interface 1030, and the communication interface 1040 are connected to each other through the bus 1050 in the device.

[0090] The processor 1010 can be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this specification.

[0091] The memory 1020 may be implemented in the form of ROM (Read Only Memory), RAM (Random Access Memory), static storage device, dynamic storage device, etc. The memory 1020 may store an operating system and other application programs. When the technical solutions provided in the embodiments of this specification are implemented by software or firmware, the relevant program codes are stored in the memory 1020 and are called and executed by the processor 1010.

[0092] The input / output interface 1030 is used to connect the input / output module to realize information input and output. The input / output module can be configured in the device as a component (not shown in the figure), or it can be externally connected to the device to provide corresponding functions. The input device may include a keyboard, a mouse, a touch screen, a microphone, various sensors, etc., and the output device may include a display, a speaker, a vibrator, an indicator light, etc.

[0093] The communication interface 1040 is used to connect a communication module (not shown) to realize communication interaction between the device and other devices. The communication module can realize communication through wired means (such as USB, network cable, etc.) or wireless means (such as mobile network, WIFI, Bluetooth, etc.).

[0094] The bus 1050 includes a path that transmits information between the various components of the device (eg, the processor 1010 , the memory 1020 , the input / output interface 1030 , and the communication interface 1040 ).

[0095] It should be noted that, although the above device only shows the processor 1010, the memory 1020, the input / output interface 1030, the communication interface 1040 and the bus 1050, in the specific implementation process, the device may also include other components necessary for normal operation. In addition, it can be understood by those skilled in the art that the above device may also only include the components necessary for implementing the embodiments of the present specification, and does not necessarily include all the components shown in the figure.

[0096] The electronic device of the above embodiment is used to implement the corresponding data processing method in any of the above embodiments, and has the beneficial effects of the corresponding method embodiment, which will not be described in detail here.

[0097] Based on the same inventive concept, corresponding to any of the above-mentioned embodiment methods, the present application also provides a non-transitory computer-readable storage medium, wherein the non-transitory computer-readable storage medium stores computer instructions, and the computer instructions are used to enable the computer to execute the data processing method described in any of the above embodiments.

[0098] The computer-readable medium of this embodiment includes permanent and non-permanent, removable and non-removable media, and information storage can be implemented by any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, read-only compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device.

[0099] The computer instructions stored in the storage medium of the above embodiments are used to enable the computer to execute the data processing method described in any of the above embodiments, and have the beneficial effects of the corresponding method embodiments, which will not be repeated here.

[0100] Based on the same inventive concept, corresponding to the data processing method described in any of the above embodiments, the present disclosure also provides a computer program product, which includes computer program instructions. In some embodiments, the computer program instructions can be executed by one or more processors of a computer so that the computer and / or the processor execute the data processing method. Corresponding to the execution subject corresponding to each step in each embodiment of the data processing method, the processor that executes the corresponding step may belong to the corresponding execution subject.

[0101] The computer program product of the above embodiment is used to enable the computer and / or the processor to execute the data processing method described in any of the above embodiments, and has the beneficial effects of the corresponding method embodiments, which will not be repeated here.

[0102] A person skilled in the art should understand that the discussion of any of the above embodiments is merely illustrative and is not intended to imply that the scope of the present application (including the claims) is limited to these examples. In line with the concept of the present application, the technical features in the above embodiments or different embodiments may be combined, the steps may be implemented in any order, and there are many other variations of the different aspects of the embodiments of the present application as described above, which are not provided in detail for the sake of simplicity.

[0103] In addition, to simplify the description and discussion, and in order not to make the embodiments of the present application difficult to understand, the known power / ground connections to the integrated circuit (IC) chip and other components may or may not be shown in the provided drawings. In addition, the device may be shown in the form of a block diagram to avoid making the embodiments of the present application difficult to understand, and this also takes into account the fact that the details of the implementation of these block diagram devices are highly dependent on the platform on which the embodiments of the present application are to be implemented (that is, these details should be fully within the scope of understanding of those skilled in the art). Where specific details (e.g., circuits) are set forth to describe exemplary embodiments of the present application, it is obvious to those skilled in the art that the embodiments of the present application can be implemented without these specific details or with changes in these specific details. Therefore, these descriptions should be considered illustrative rather than restrictive.

[0104] Although the present application has been described in conjunction with specific embodiments of the present application, many alternatives, modifications and variations of these embodiments will be apparent to those skilled in the art from the foregoing description. For example, other memory architectures (e.g., dynamic RAM (DRAM)) may use the discussed embodiments.

[0105] The embodiments of the present application are intended to cover all such substitutions, modifications and variations that fall within the broad scope of the appended claims. Therefore, any omissions, modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the embodiments of the present application should be included in the scope of protection of the present application.

Claims

1. A data processing method, characterized in that: include: In response to a flash sale request event from a user, obtaining first inventory information of a product corresponding to the flash sale request from a Redis cache; The Redis cache is pre-loaded with inventory information of all products; Verifying the first inventory information to obtain a first verification result, and performing a first operation on the first inventory information based on the first verification result; The result of the first operation is synchronized to a database, and the second inventory information of the corresponding product is verified in the database to obtain a second verification result, and a flash sale result is returned to the user based on the second verification result.

2. The method according to claim 1, characterized in that The verifying the first inventory information to obtain a first verification result, and performing a first operation on the first inventory information based on the first verification result, includes: Get the quantity of products corresponding to the flash sale request; comparing the commodity quantity with the first inventory information, and in response to the first inventory information being greater than the commodity quantity, performing a pre-deduction operation on the first inventory information; In response to the first inventory information being less than the commodity quantity, the first inventory information is kept unchanged, and a user is prompted that the inventory is insufficient.

3. The method according to claim 1, characterized in that The step of synchronizing the result of the first operation to a database includes: Sending the result of the first operation to a database; Using a database query statement, based on the result of the first operation, the second inventory is synchronously deducted.

4. The method according to claim 3, characterized in that The verifying the second inventory information of the corresponding product in the database to obtain a second verification result, and returning a flash sale result to the user based on the second verification result, includes: Determining whether the second verification result after the synchronous deduction process is greater than or equal to zero; In response to the second verification result being greater than or equal to zero, the first operation result is synchronized to the transaction success in the database, and a purchase success result is returned to the user; In response to the second verification result being less than zero, the transaction in which the first operation result is synchronized to the database fails, the transaction is rolled back, and a user is prompted that the inventory is insufficient.

5. The method according to claim 4, characterized in that The method further includes: adding a first constraint to the database; the first constraint is to restrict the inventory information in the database to not be a negative number; After the first operation result is successfully synchronized to the transaction in the database, the method further includes: Determining whether a field of the second inventory information in the database satisfies a first constraint; In response to the field of the second inventory information not satisfying the first constraint, the transaction is rolled back, and a user is prompted that the inventory is insufficient.

6. The method according to claim 1, characterized in that After synchronizing the result of the first operation to the database, the method further includes: Verify the order number corresponding to the flash sale request; In response to the order number being unique, continuing the inventory verification operation; In response to the order number being not unique, a request error message is returned to the user.

7. A data processing device, characterized in that: include: an acquisition module, configured to, in response to a flash sale request event of a user, acquire first inventory information of a product corresponding to the flash sale request from a Redis cache; The Redis cache is pre-loaded with inventory information of all products; a verification module, configured to verify the first inventory information, obtain a first verification result, and perform a first operation on the first inventory information based on the first verification result; The return module is configured to synchronize the result of the first operation to the database, verify the second inventory information of the corresponding product in the database, obtain a second verification result, and return the flash sale result to the user based on the second verification result.

8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the method according to any one of claims 1 to 6 is implemented.

9. A non-transitory computer-readable storage medium storing computer instructions, characterized in that: The computer instructions are used to enable a computer to execute the method according to any one of claims 1 to 6.

10. A computer program product, comprising computer program instructions, which, when executed on a computer, cause the computer to execute the method according to any one of claims 1 to 6.

Citation Information

Patent Citations

  • Commodity seckilling method and device, computer equipment and storage medium

    CN112132662A

  • High-concurrency payment order anti-duplication method, device, system and equipment, medium and program product

    CN115374098A

  • Caching-based method and system for sales locking

    WO2020192063A1