Improvement method of Redis distributed lock based on Mysql database
What is Al technical title?
Al technical title is built by PatSnap Al team. It summarizes the technical point description of the patent document.
A distributed lock and database technology, applied in database update, database distribution/replication, electronic digital data processing, etc.
Pending Publication Date: 2022-01-07
大唐互联科技(武汉)有限公司 +1
View PDF0 Cites 0 Cited by
Summary
Abstract
Description
Claims
Application Information
AI Technical Summary
This helps you quickly interpret patents by identifying the three key elements:
Problems solved by technology
Method used
Benefits of technology
Problems solved by technology
In this way, Redis distributed locks can solve most of the concurrency problems, but there is a special case of concurrency problems that Redis distributed locks cannot avoid
Method used
the structure of the environmentally friendly knitted fabric provided by the present invention; figure 2 Flow chart of the yarn wrapping machine for environmentally friendly knitted fabrics and storage devices; image 3 Is the parameter map of the yarn covering machine
View more
Image
Smart Image Click on the blue labels to locate them in the text.
Viewing Examples
Smart Image
Click on the blue label to locate the original text in one second.
Reading with bidirectional positioning of images and text.
Smart Image
Examples
Experimental program
Comparison scheme
Effect test
Embodiment 1
[0020] The order modification operation prevents multiple threads from modifying the order at the same time:
[0021] s11. A user is modifying an order. Before modifying the information of order A, the corresponding thread 1 uses the SetNX command of Redis to set the value and expiration time for the business key of order A. If the setting fails, it means that thread 1 has not After acquiring the lock, thread 1 terminates the operation; if the setting is successful, thread 1 enters s12;
[0022] S12. Thread 1 updates the status of order A in the Mysql database order table to "operating". If the update result returns 1, it means that there is no thread performing operations related to order A at this time, that is, there is no concurrency, and enters s13 ; If the update result returns 0, it means that other threads are performing operations related to order A at this time, and thread 1 terminates the operation;
[0023] S13. Thread 1 executes the update operation of order A; r...
Embodiment 2
[0025] Flash kill activities to prevent oversold scenarios
[0026] S21. A user is conducting a flash sale of product A. Before snapping up, the corresponding thread 1 checks whether the inventory of product A is greater than zero. If it is less than zero, thread 1 terminates the operation; if it is greater than zero, then enters S22;
[0027] S22. Thread 1 uses the SetNX command of Redis to set the value and expiration time for the business key corresponding to commodity A in the inventory table. If the setting fails, it means that thread 1 has not acquired the lock, and thread 1 terminates the operation; if the setting is successful, thread 1 enter s23;
[0028] S23. Thread 1 updates the status of commodity A in the inventory table of the Mysql database to "operating". If the update result returns 1, it means that there is no thread performing operations related to commodity A inventory at this time, that is, there is no concurrency, enter s4; if the update result returns 0...
the structure of the environmentally friendly knitted fabric provided by the present invention; figure 2 Flow chart of the yarn wrapping machine for environmentally friendly knitted fabrics and storage devices; image 3 Is the parameter map of the yarn covering machine
Login to view more
PUM
Login to view more
Abstract
The invention discloses an improvement method and device for a Redis distributed lock based on a Mysql database, and the method comprises the steps: setting a value and expiration time for a business key by using a SetNX command of Redis before a thread 1 carries out an A operation, and if the setting fails, enabling the thread 1 to terminate the operation; if the setting is successful, entering the next step; enabling the thread 1 to update the state of corresponding data t in a table data table a related to the operation A in the Mysql database into an 'in-operation' state, if an updating result returns to 1, determining that no thread carries out the operation related to the data t at the moment, and the next step is carried out; if the update result returns to 0, enabling the thread 1 to terminate the operation; enabling the thread 1 to execute the operation A; wherein no matter whether the thread 1 executes the operation A successfully or not, the state of the data t of the table a is updated to be 'non-operation', and the corresponding Redis key in the first step is deleted. The method has the beneficial effect that the concurrency problem generated when multiple threads simultaneously obtain the Redis distributed lock under the high concurrency condition is solved.
Description
technical field [0001] The invention relates to the field, in particular to an improved method of a Redis distributed lock based on a Mysql database. Background technique [0002] As the number of system application users continues to increase, the single service architecture can no longer meet the needs. Therefore, the microservice architecture came into being. The microservice architecture adopts a distributed deployment method, that is, the same service can be deployed on multiple machines. In the case of high concurrency, in order to prevent the same resource from being used by two or more threads at the same time and cause concurrency problems, you can use Java concurrency control-related APIs (Synchronized or ReentrantLock) to solve it. However, with the emergence of distributed systems, multi-threaded and multi-processes will be distributed on different servers, which makes the Java concurrency control API unable to solve the concurrency problems among distributed sy...
Claims
the structure of the environmentally friendly knitted fabric provided by the present invention; figure 2 Flow chart of the yarn wrapping machine for environmentally friendly knitted fabrics and storage devices; image 3 Is the parameter map of the yarn covering machine
Login to view more
Application Information
Patent Timeline
Application Date:The date an application was filed.
Publication Date:The date a patent or application was officially published.
First Publication Date:The earliest publication date of a patent with the same application number.
Issue Date:Publication date of the patent grant document.
PCT Entry Date:The Entry date of PCT National Phase.
Estimated Expiry Date:The statutory expiry date of a patent right according to the Patent Law, and it is the longest term of protection that the patent right can achieve without the termination of the patent right due to other reasons(Term extension factor has been taken into account ).
Invalid Date:Actual expiry date is based on effective date or publication date of legal transaction data of invalid patent.