当前位置:网站首页>Redis distributed lock
Redis distributed lock
2022-07-19 08:10:00 【Program three two lines】
One 、 Common distributed locks
Based on database
be based on redis Realization ( The highest performance )
be based on zookeeper Realization ( Highest reliability )
Two 、 be based on redis Realize distributed locking
1、 command
1、 Set lock command :setnx key_name value
setnx users 10
Then perform setnx user 20 return 0 operation failed Because it's locked
2、 Release the lock command :del key_name
del users
3、 Expiration settings command :expire key_name value
expire users 20
That is, lock and set the expiration time to make the operation called atomic operation
set users 10 nx ex 122、java Code


3、 ... and 、uuid Prevent accidental deletion of lock operation
Problem analysis

solve
Set up different uuid, When releasing the lock, judge the current uuid And the lock to be released uuid Whether or not the same
The above code is modified
Set up uuid

Compare release

Four 、lua Ensure atomicity of deletion



![]()


边栏推荐
- Redis transaction
- First experience of openvino machine learning
- Forecast sales xgboost
- If a number in C language is exactly equal to the sum of its factors, this number is called "perfect". For example, 6=1 + 2 + 3 programming
- unity 自定义天空球模型防止被裁剪
- Why does the Fed cut interest rates benefit the digital money market in the long run? 2020-03-05
- Jira --- workflow call external api
- CCF-CSP《202206-2—寻宝!大冒险!》
- the max_iter was reached which means the coef_ did not converge “the coef_ did not converge“
- Beijing Jiewen technology, an acquiring outsourcing service provider, transferred 60% of its shares for about 480million
猜你喜欢

Array exercise 3

YOLOV5-打标签建立自己的数据集

High performance integrated video image processing board based on ultrascale FPGA + Huawei Hisilicon arm / fpga+arm

mySQL 2502 2503错误

黑马程序员-软件测试-16阶段3-功能测试-175-198,URL组成介绍,请求内容以及组成说明行功能测试与数据库,url组成扩展说明,客户端与服务器请求与响应,-Fiddler按照以及功能检查确认,

半导体材料技术

redis集群

First experience of openvino machine learning

Modify scroll bar style

怎么检查APP是否存在用户信息数据泄露漏洞
随机推荐
本地存储 sessionStorage
Export file or download file
How to use curl in Jenkins pipeline and process response results
Pytorch notes (5)
First experience of openvino machine learning
如何在 Jenkins Pipeline 中使用curl 并处理响应结果
深度学习之 7 深度前馈网络2
KingbaseES 中可以通过构造一个聚集函数来实现mysql的any_value功能。
[C # console] - C # console class
[MySQL] transaction: basic knowledge of transaction, implementation principle of MySQL transaction, detailed explanation of transaction log redolog & undo
Pytoch notes (1)
Why does the Fed cut interest rates benefit the digital money market in the long run? 2020-03-05
Go语言圣经
Understand LSTM and Gru
Stm32f103c8t6 hardware IIC control 4-pin 0.96 inch OLED display
Discussion sur la technologie RISC - V
[JVM] heap memory, escape analysis, on stack allocation, synchronous omission, scalar replacement details
How to write the highlights of SCI papers (seriously teach you how to write)
【刷题篇】完全平方数
RISC-V技術雜談