Distributed lock implementation method and system based on redis
A technology of distributed locks and implementation methods, applied in the direction of micro-control devices, etc., can solve problems such as concurrent access, and achieve the effects of convenient business expansion, simplified development, and good scalability
- Summary
- Abstract
- Description
- Claims
- Application Information
AI Technical Summary
Problems solved by technology
Method used
Image
Examples
Embodiment 1
[0068] as attached figure 1 As shown, the redis-based distributed lock implementation method of the present invention is as follows:
[0069] S1. Get the current time, in milliseconds;
[0070] S2. Request locks from the redis master node in sequence;
[0071] S3. The client sets the network connection and response timeout time, and the response timeout time is less than the lock's failure time (assuming that the lock's automatic failure time is 10 seconds, the timeout time is generally between 5-50 milliseconds, let's assume that the timeout time is 50ms) ); if the response timeout expires, skip the redis master node and try the next redis master node;
[0072] S4. The client uses the current time minus the time to start acquiring the lock to obtain the usage time for acquiring the lock:
[0073] If and only if more than half (N / 2+1, here is 5 / 2+1=3 nodes) of the redis master nodes acquire the lock, and the usage time of acquiring the lock is less than the lock failure tim...
Embodiment 2
[0101] The distributed lock implementation system based on redis of the present invention includes,
[0102] Get module, used to get the current time, in milliseconds;
[0103] The request module is used to request locks from the redis master node in sequence;
[0104] The setting module is used to set the network connection and response timeout time through the client. The response timeout time is less than the lock expiration time; if the response timeout time expires, skip the redis master node and try the next redis master node;
[0105] The calculation module is used to subtract the starting time of acquiring the lock from the current time used by the client to obtain the usage time of acquiring the lock:
[0106] The judgment module is used to judge whether more than half of the redis master nodes have obtained the lock, and the usage time of acquiring the lock is less than the lock expiration time:
[0107] If so, the lock is successfully acquired, and the real effect...
Embodiment 3
[0110] The present invention also provides an electronic device, comprising: a memory and at least one processor;
[0111] wherein, the memory stores computer-executed instructions;
[0112] The at least one processor executes the computer-executable instructions stored in the memory, so that the at least one processor executes the redis-based distributed lock implementation method according to any one of the present invention.
[0113] The processor may be a central processing unit (CPU), other general-purpose processors, digital signal processors (DSPs), application specific integrated circuits (ASICs), off-the-shelf programmable gate arrays (FPGAs) or other programmable logic devices, discrete Gate or transistor logic devices, discrete hardware components, etc. The processor may be a microprocessor or the processor may be any conventional processor or the like.
[0114]The memory can be used to store computer programs and / or modules, and the processor implements various f...
PUM
Login to View More Abstract
Description
Claims
Application Information
Login to View More 
