Improvement method of Redis distributed lock based on Mysql database

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

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
  • Improvement method of Redis distributed lock based on Mysql database
  • Improvement method of Redis distributed lock based on Mysql database

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

No 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
no application Login to view more
Patent Type & Authority Applications(China)
IPC IPC(8): G06F16/23G06F16/2458G06F16/27
CPCG06F16/2343G06F16/2471G06F16/27
Inventor 孙绍利王艳霞徐军李军章书乐詹开洪何宁波
Owner 大唐互联科技(武汉)有限公司
Who we serve
  • R&D Engineer
  • R&D Manager
  • IP Professional
Why Eureka
  • Industry Leading Data Capabilities
  • Powerful AI technology
  • Patent DNA Extraction
Social media
Try Eureka
PatSnap group products