Unlock instant, AI-driven research and patent intelligence for your innovation.

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

Pending Publication Date: 2022-05-24
SHANDONG LANGCHAO YUNTOU INFORMATION TECH CO LTD
View PDF0 Cites 0 Cited by
  • Summary
  • Abstract
  • Description
  • Claims
  • Application Information

AI Technical Summary

Problems solved by technology

[0006] The technical task of the present invention is to provide a redis-based distributed lock implementation method and system to solve the problem of how to use redis distributed locks to handle concurrent access to data and ensure the final consistency of data

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
  • Distributed lock implementation method and system based on redis

Examples

Experimental program
Comparison scheme
Effect test

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...

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 a redis-based distributed lock implementation method and system, belongs to the technical field of java under a micro-service architecture, and aims to solve the technical problem of how to process concurrent access of data for a redis distributed lock and ensure final consistency of the data. According to the technical scheme, the method specifically comprises the following steps: acquiring current time in milliseconds; requesting to lock the redis master node according to the sequence; the client sets network connection and response timeout time, wherein the response timeout time is smaller than the failure time of the lock; if the response timeout time is overtime, the redis master node is skipped, and a next redis master node is tried; the client subtracts the time for starting to obtain the lock from the current time to obtain the use time for obtaining the lock: when and only when more than half of redis master nodes obtain the lock and the use time for obtaining the lock is less than the lock failure time, the lock is successfully obtained, and the use time for obtaining the lock needs to be subtracted from the real effective time for obtaining the lock; and when the lock acquisition fails, the client unlocks on all the redis master nodes.

Description

technical field [0001] The invention relates to the technical field of java under a micro-service architecture, in particular to a redis-based distributed lock implementation method and system. Background technique [0002] In many scenarios, in order to ensure the eventual consistency of data, many technical solutions are required, such as distributed locks. When developing applications, if concurrent access to a shared variable is required, distributed locks can be used for processing. [0003] In order to ensure that a method or property can only be executed by one visitor at the same time under high concurrency, in the case of single-machine deployment of traditional monolithic applications, functions related to concurrent processing can be used for mutual exclusion control. However, with the needs of business development, after the original single-machine deployment system is evolved into a distributed cluster system, since the distributed system is multi-threaded, mul...

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): G06F9/22
CPCG06F9/22
Inventor 刘建邦徐士强董玉全
Owner SHANDONG LANGCHAO YUNTOU INFORMATION TECH CO LTD