Inventory management method and system based on Redis, application method of inventory management method and system and electronic equipment
Through the Redis inventory queue module and SpringBoot's StringRedisTemplate, the asynchronous processing of inventory deductions is achieved, solving the problem of inventory management system pressure under high concurrency, improving performance and security, and simplifying structure and maintenance.
Patent Information
- Application Number
- CN202310648416.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-02
- Publication Date
- 2024-12-03
AI Technical Summary
In the high concurrency scenario, the inventory management system caused by the use of pessimistic locks is under great pressure and low processing power, and only one request is allowed to succeed and other requests fail, resulting in thread retry and system pressure increases.
Through the Redis inventory queue module, LPUSH and RPOP commands are used to realize asynchronous processing, identify the inventory deduction instructions in the user request, and determine whether the remaining inventory meets the requirements. If it is satisfied, it will be saved in the queue. If it is not satisfied, it will be insufficient. Combined with SpringBoot's StringRedisTemplate performs asynchronous deduction processing.
The structure of the inventory management module is simplified, the maintenance is simple and scalable, and the system pressure is reduced in high concurrency scenarios, improving performance and data concurrency security.
Smart Images

Figure CN119067561A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of inventory data deduction, and more specifically, to a management method for implementing high-concurrency inventory increase and decrease based on Redis. In addition, the present application also relates to a management system for implementing high-concurrency inventory increase and decrease based on Redis, an application method for implementing a high-concurrency inventory increase and decrease management method based on Redis, and an electronic device. Background Art
[0002] Digitalization is the current trend of business development. When managing material inventory through digital technology, it is necessary to deduct a certain material inventory. However, a large number of users requesting to operate the same inventory at the same time will cause an uncontrollable situation for the system inventory.
[0003] In the prior art, the problem of asynchronous decoupling is generally solved by using distributed locks and middleware such as RabbitMQ and Kafka. For example, using Zookeeper, Redis, and MySQL to implement distributed locks, all subsequent operations must be performed based on the premise of obtaining locks; asynchronous processing is implemented through message middleware, peak-shaving and valley-filling are used to handle the large number of requests that flow in instantly, and queues are used to process them asynchronously at a uniform speed.
[0004] However, the existing technical solutions have the following problems. When using the solution implemented with pessimistic locking, only one request is allowed to succeed, and the rest of the requests fail, resulting in thread retries and increased system pressure, and low high-concurrency business processing capabilities.
[0005] Therefore, how to provide a management method based on Redis to achieve high-concurrency inventory increase and decrease, which can simplify the structure of the inventory management module, simplify maintenance, and have strong scalability, and reduce system pressure in high-concurrency scenarios has become a technical problem that needs to be urgently solved by technical personnel in this field. Summary of the invention
[0006] In order to solve the above technical problems, the present application provides a management method for implementing high-concurrency inventory increase and decrease based on Redis, which can simplify the structure of the inventory management module, is simple to maintain, and has strong scalability, and reduces system pressure in high-concurrency scenarios. In addition, the present application also relates to a management system for implementing high-concurrency inventory increase and decrease based on Redis, an application method for implementing a high-concurrency inventory increase and decrease management method based on Redis, and an electronic device, which also have the above beneficial effects.
[0007] The technical solutions provided by this application are as follows:
[0008] The present application provides a management method for realizing high-concurrency inventory increase and decrease based on Redis, the method comprising the following steps: obtaining first request information, the first request information coming from a user client; performing numerical judgment analysis on the first request information through a Redis inventory queue module, identifying the first request information that can meet the deduction quantity requirement, and saving it in a first queue, the first queue being a Redis inventory queue associated with a specified number of items; performing deduction processing on inventory data according to the first queue.
[0009] Furthermore, in a preferred embodiment of the present invention, the “deducting the inventory data according to the first queue” specifically includes the following steps: combining the StringRedisTemplate of SpringBoot, deducting the inventory data in the database according to the first queue.
[0010] Furthermore, in a preferred embodiment of the present invention, the deduction process is an asynchronous deduction process.
[0011] Further, in a preferred embodiment of the present invention, the "identifying the first request information that can meet the deduction quantity requirement and saving it in the first queue" specifically includes the following steps: analyzing the first request information to identify the quantity to be deducted; comparing the quantity to be deducted with the remaining quantity in the first queue; if satisfied, outputting a first specific value to the client and saving the first request information in the first queue; if not satisfied, outputting a second specific value to the client.
[0012] Furthermore, in a preferred embodiment of the present invention, the first specific value is a prompt of successful deduction or the remaining amount after deduction; the second specific value is a prompt of failed deduction or a null value.
[0013] Furthermore, in a preferred embodiment of the present invention, the management method further comprises the following steps: when it is identified that the Redis inventory queue module issues the second specific value, issuing a prompt that the quantity of corresponding items in the first queue is insufficient.
[0014] Furthermore, in a preferred embodiment of the present invention, the “saving in the first queue” specifically includes the following steps: the Redis inventory queue module performs left-in and right-out queue management of the first request information on the first queue through LPUSH and RPOP commands.
[0015] In addition, the present application also provides a management system for implementing high-concurrency inventory increases and decreases based on Redis. The system is used to execute the above-mentioned management method for implementing high-concurrency inventory increases and decreases based on Redis. The management system includes: a first acquisition module, the first acquisition module is used to obtain first request information, and the first request information comes from a user client; a first analysis module, the first analysis module is used to perform a numerical judgment analysis on the first request information through a Redis inventory queue module, identify the first request information that can meet the deduction quantity requirements, and save it in a first queue; a first execution module, the first execution module is used to perform deduction processing on inventory data according to the first queue.
[0016] In addition, the present application also provides an application method for implementing a high-concurrency inventory increase and decrease management method based on Redis, including: in the inventory management system, introducing a Redis inventory queue module based on the SpringBoot framework, and introducing dependencies for implementing Redis data management; based on the configuration file application in the SpringBoot framework, configuring the Redis inventory queue module; wherein, writing and executing the algorithm for implementing the above-mentioned high-concurrency inventory increase and decrease management method based on Redis.
[0017] In addition, the present application also provides an electronic device, including: a computer program, the computer program is used to execute the above-mentioned Redis-based high-concurrency inventory increase and decrease management method; a memory, the memory is used to store the computer program; and a processor, the processor is used to execute the computer program.
[0018] The present invention provides a management method for realizing high-concurrency inventory increase and decrease based on Redis. Compared with the prior art, after obtaining the first request information from the user client, the Redis inventory queue module identifies and parses the first request information to obtain the inventory deduction instruction for the specified item, and judges whether the remaining inventory of the current first queue meets the requirements according to the inventory deduction instruction; if it meets the requirements, the inventory deduction instruction is saved in the first queue, so that Redis can process one by one in a single thread and deduct the inventory data of the corresponding items. The technical solution provided by the present application can simplify the structure of the inventory management module, is simple to maintain, and has strong scalability, and reduces system pressure in high-concurrency scenarios.
[0019] The beneficial effects of this program include:
[0020] 1. Based on the single-threaded characteristics of redis and the high-performance characteristics based on memory operations, it can effectively solve the performance problems and data concurrency security problems in high concurrency situations.
[0021] 2. The bidirectional linked list structure based on redis reduces the complexity of the system, is easy to maintain, and is easy to expand. When we need to increase or decrease inventory, we only need to delete the corresponding key. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0023] Figure 1 A flow chart of a method for managing high-concurrency inventory increase and decrease based on Redis provided in an embodiment of the present invention;
[0024] Figure 2 A schematic diagram of the execution logic of a method for managing high-concurrency inventory increase and decrease based on Redis provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0025] In order to enable those skilled in the art to better understand the technical solutions in the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without creative work are within the scope of protection of this application.
[0026] It should be noted that when an element is referred to as being "fixed on" or "set on" another element, it can be directly on the other element or indirectly set on the other element; when an element is referred to as being "connected to" another element, it can be directly connected to the other element or indirectly connected to the other element.
[0027] It should be understood that the terms "length", "width", "up", "down", "front", "back", "first", "second", "vertical", "horizontal", "top", "bottom", "inside", "outside", etc., indicating the orientation or position relationship, are based on the orientation or position relationship shown in the drawings, and are only for the convenience of describing the present application and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore should not be understood as a limitation on the present application.
[0028] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the features. In the description of this application, "multiple" and "several" mean two or more, unless otherwise clearly and specifically defined.
[0029] It should be noted that the structures, proportions, sizes, etc. illustrated in the drawings of this specification are only used to match the contents disclosed in the specification for people familiar with this technology to understand and read, and are not used to limit the conditions under which this application can be implemented. Therefore, they have no substantive technical significance. Any structural modification, change in proportional relationship or adjustment of size should still fall within the scope of the technical content disclosed in this application without affecting the effects and purposes that can be achieved by this application.
[0030] like Figure 1 to Figure 2 As shown, an embodiment of the present application provides a management method for implementing high-concurrency inventory increase and decrease based on Redis, the method comprising the following steps: obtaining first request information, the first request information coming from a user client; performing numerical judgment analysis on the first request information through a Redis inventory queue module, identifying the first request information that can meet the deduction quantity requirement, and saving it in a first queue, the first queue being a Redis inventory queue associated with a specified number of items; performing deduction processing on inventory data according to the first queue.
[0031] The present invention provides a technical solution for a management method of high-concurrency inventory increase and decrease based on Redis. After obtaining the first request information from the user client, the Redis inventory queue module identifies and parses the first request information to obtain the inventory deduction instruction for the specified item, and judges whether the remaining inventory of the current first queue meets the requirements according to the inventory deduction instruction; if it meets the requirements, the inventory deduction instruction is saved in the first queue, so that Redis can perform single-threaded processing one by one and deduct the inventory data of the corresponding items. The technical solution provided by the present application can simplify the structure of the inventory management module, is simple to maintain, and has strong scalability, and reduces system pressure in high-concurrency scenarios.
[0032] It should be noted that, since the data structure in the Redis inventory queue module is a bidirectional linked list structure of a List list, the effect of quickly inserting the head and tail elements can be achieved at the same time, thereby improving the efficiency of inventory management. Furthermore, since the Redis inventory queue module is loaded into the system memory, combined with the multi-channel, large bandwidth, and high response characteristics of the memory, the efficiency of quickly processing high-concurrency deduction requests is further improved. In addition, the present application also relates to a management system, application method, and electronic device for realizing high-concurrency inventory increase and decrease based on Redis, which also has the above-mentioned beneficial effects.
[0033] Specifically, in an embodiment of the present invention, the "deduction processing of inventory data according to the first queue" specifically includes the following steps: combining with SpringBoot's StringRedisTemplate, deduction processing of inventory data in the database according to the first queue.
[0034] It should be noted that the Spring framework is an open source application framework based on the Java language. S pr i ng The StringRedisTemplate module in the Boot development framework can quickly operate the Redis inventory queue. Before using it, configure the Redis connection information through the application file, such as:
[0035]
[0036] Specifically, in an embodiment of the present invention, the deduction process is an asynchronous deduction process.
[0037] It should be noted that based on the characteristics of the bidirectional linked list structure of the Redis data structure, it is possible to implement synchronous or asynchronous deduction processing, cache the operations to be processed, and then realize the processing of high-concurrency data, which can reduce system pressure.
[0038] Specifically, in an embodiment of the present invention, the step of "identifying the first request information that can meet the deduction quantity requirement and saving it in the first queue" specifically includes the following steps: analyzing the first request information to identify the quantity to be deducted; comparing the quantity to be deducted with the remaining quantity in the first queue; if satisfied, outputting a first specific value to the client and saving the first request information in the first queue; if not satisfied, outputting a second specific value to the client.
[0039] It should be noted that when the first request information is received, a quick judgment of the request is implemented based on the Redis inventory queue module, and feedback is given to the outside for both situations that can be satisfied and those that cannot be satisfied, thereby realizing the experience of using the system.
[0040] Specifically, in an embodiment of the present invention, the first specific value is a prompt of successful deduction or the remaining amount after deduction; the second specific value is a prompt of failed deduction or a null value.
[0041] Specifically, in an embodiment of the present invention, the management method further includes the following steps: when it is identified that the Redis inventory queue module issues the second specific value, issuing a prompt that the quantity of corresponding items in the first queue is insufficient.
[0042] It should be noted that by issuing a prompt that the quantity of the corresponding item is insufficient, the manager can be helped to replenish the related items or remove the item / goods from the shelf.
[0043] Specifically, in an embodiment of the present invention, the “saving in the first queue” specifically includes the following steps: the Redis inventory queue module performs left-in and right-out queue management of the first request information on the first queue through LPUSH and RPOP commands.
[0044] It should be noted that the Redis inventory queue module implements asynchronous unreliable queues through LPUSH and RPOP commands.
[0045] In addition, the present application also provides a management system for implementing high-concurrency inventory increase and decrease based on Redis, the system is used to execute the above-mentioned management method for implementing high-concurrency inventory increase and decrease based on Redis, the management system includes: a first acquisition module, the first acquisition module is used to obtain first request information, the first request information comes from the user client; a first analysis module, the first analysis module is used to perform numerical judgment analysis on the first request information through the Redis inventory queue module, identify the first request information that can meet the deduction quantity requirements, and save it in the first queue; a first execution module, the first execution module is used to perform deduction processing on inventory data according to the first queue. The technical solution of a management system for implementing high-concurrency inventory increase and decrease based on Redis provided in the present application also has the above-mentioned beneficial effects.
[0046] In addition, the present application also provides an application method for implementing a high-concurrency inventory increase and decrease management method based on Redis, including: in the inventory management system, introducing a Redis inventory queue module based on the SpringBoot framework, and introducing a dependency for implementing Redis data management; configuring the Redis inventory queue module based on the configuration file application in the SpringBoot framework; wherein, writing and executing the algorithm for implementing the above-mentioned high-concurrency inventory increase and decrease management method based on Redis. The technical solution of an application method for implementing a high-concurrency inventory increase and decrease management method based on Redis provided in the present application also has the above-mentioned beneficial effects.
[0047] In addition, the present application also provides an electronic device, including: a computer program, the computer program is used to execute the above-mentioned management method for realizing high-concurrency inventory increase and decrease based on Redis; a memory, the memory is used to store the computer program; the processor is used to execute the computer program. The technical solution of an electronic device provided by the present application also has the above-mentioned beneficial effects.
[0048] It is necessary to add that, if Figure 2 As shown, the design principle of this scheme is:
[0049] 1. This design uses the Redis data structure: the bidirectional linked list structure of the List list, which has the feature of very fast insertion of elements from the beginning to the end. LPUSH and RPOP can be used directly to implement the queue mode. At the same time, it uses the high performance of Redis based on memory operation and its suitable thread model: I / O multiplexing, avoiding context switching, single thread model, etc.
[0050] Based on the above, StringRedisTemplate combined with SpringBoot implements the safety deduction of the corresponding item inventory in concurrent scenarios. When the user request reaches Redis, redis executes one by one in a single thread, and returns a value or null each time. When there is a value, it means that the inventory is sufficient, and it is dequeued (consumed) at the same time. When there is no null returned in redis (queue), there is no inventory. Subsequent corresponding processing can be performed according to the returned result.
[0051] 2. When multiple clients concurrently deduct the inventory of product A, the interface receives the request and accesses the inventory queue of A. If there is sufficient inventory, the user will be responded to with the corresponding logic of sufficient inventory. If there is no inventory of A, or the inventory quantity is insufficient for the request, the corresponding logic of insufficient inventory will be executed and responded to the client user after the execution is completed. The consistency between redis and the database can also be achieved through asynchronous processing later.
[0052] It should be noted that Redis needs to be configured before use. The configuration steps are as follows:
[0053] 1. Use SpringBoot to integrate Redis. Introduce related dependencies
[0054]
[0055] 2. Configure redis for the application file. For example
[0056]
[0057] 3. Add the inventory queue (LPUSH) of the specified material and remove the inventory (RPOP) method
[0058]
[0059]
[0060] 4. Execute logic every time a user requests it
[0061]
[0062] When using the technology of the present invention, please note that:
[0063] Code related instructions:
[0064] 1. The core class code is RedisServiceImpl, which implements the methods of the interface class RedisService.
[0065] ① The addEntriesOnListLeft() method is used to add material inventory. The input parameters are the material code (commodity code) and the inventory collection. The principle can be understood as adding the inventory to a queue, and the queue name is its material code.
[0066] ②The removeOneEntryOnListRight() method is an inventory deduction method. The principle can be understood as queue consumption. We can consume as much inventory as we need to deduct.
[0067] #The following are demo tests and usage examples
[0068] 2. Test02 is a test class that simulates multiple threads deducting the inventory of the same material at the same time.
[0069] 3. Interface / redis / addStock is used to add the inventory interface for simulation testing. The parameter material code or product code materialCode and the product inventory quantity are passed in.
[0070] 4. The interface / redis / addStock / getMaterialHasStock is a simulated user request submission interface. The user client places an order or a rush purchase request to this interface.
[0071] The interface uses the removeOneEntryOnListRight method to determine whether the current request has obtained inventory. If not, it will return a prompt to the user to inform that there is no inventory. If the inventory is obtained, the subsequent related logic of having inventory will be executed.
[0072] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A management method for realizing high-concurrency inventory increase and decrease based on Redis, characterized in that: The management method includes the following steps: Obtaining first request information, where the first request information comes from a user client; Performing numerical judgment and analysis on the first request information through the Redis inventory queue module; Identify the first request information that can meet the deduction quantity requirement and save it in a first queue; The first queue is a Redis inventory queue associated with a specified number of items; According to the first queue, deduction processing is performed on the inventory data.
2. According to claim 1, the management method for realizing high concurrent inventory increase and decrease based on Redis is characterized in that: The “deduction processing of inventory data according to the first queue” specifically includes the following steps: Combined with SpringBoot's StringRedisTemplate, the inventory data in the database is deducted according to the first queue.
3. According to claim 2, the management method for realizing high concurrent inventory increase and decrease based on Redis is characterized in that: The deduction process is an asynchronous deduction process.
4. According to claim 2, the management method for realizing high-concurrency inventory increase and decrease based on Redis is characterized in that: The step of "identifying the first request information that can meet the deduction quantity requirement and storing it in the first queue" specifically includes the following steps: Analyzing the first request information to identify the amount to be deducted; Compare the quantity to be deducted with the remaining quantity in the first queue; If satisfied, output the first specific value to the client, and save the first request information in the first queue; If not satisfied, a second specific value is output to the client.
5. According to claim 4, the management method for realizing high concurrent inventory increase and decrease based on Redis is characterized in that: The first specific value is a successful deduction prompt or the remaining amount after deduction; The second specific value is a deduction failure prompt or a null value.
6. According to claim 5, the management method for realizing high-concurrency inventory increase and decrease based on Redis is characterized in that: The management method also includes the following steps: When it is identified that the Redis inventory queue module issues the second specific value, a prompt is issued that the quantity of corresponding items in the first queue is insufficient.
7. According to claim 1, the management method for realizing high concurrent inventory increase and decrease based on Redis is characterized in that: The "saving in the first queue" specifically includes the following steps: The Redis inventory queue module performs left-in and right-out queue management of the first request information on the first queue through LPUSH and RPOP commands.
8. A management system based on Redis to achieve high-concurrency inventory increase and decrease, characterized in that: The system is used to execute the management method for realizing high-concurrency inventory increase and decrease based on Redis according to any one of claims 1 to 7, and the management system includes: A first acquisition module, the first acquisition module is used to acquire first request information, the first request information comes from a user client; A first analysis module, the first analysis module is used to perform a numerical judgment analysis on the first request information through a Redis inventory queue module, identify the first request information that can meet the deduction quantity requirement, and save it in a first queue; A first execution module is used to perform a deduction process on the inventory data according to the first queue.
9. An application method for implementing a high-concurrency inventory increase and decrease management method based on Redis, characterized in that: include: In the inventory management system, the Redis inventory queue module is introduced based on the SpringBoot framework, and the dependency for implementing Redis data management is introduced; Based on the configuration file application in the SpringBoot framework, configure the Redis inventory queue module; in, Write and execute the algorithm of the management method for realizing high-concurrency inventory increase and decrease based on Redis as described in any one of claims 1 to 7.
10. An electronic device, characterized in that include: A computer program, the computer program being used to execute the management method for realizing high-concurrency inventory increase and decrease based on Redis according to any one of claims 1 to 7; A memory, the memory being used to store the computer program; A processor is used to execute the computer program.
