当前位置:网站首页>redis分布式锁
redis分布式锁
2022-07-17 05:57:00 【程序三两行】
一、常见分布式锁
基于数据库实现
基于redis实现(性能最高)
基于zookeeper实现(可靠性最高)
二、基于redis实现实现分布式锁
1、命令
1、设置锁 命令:setnx key_name value
setnx users 10
接着执行 setnx user 20 返回0 操作失败 因为上锁了
2、释放锁 命令:del key_name
del users
3、过期设置 命令:expire key_name value
expire users 20
即上锁又设置过期时间使操作称为原子操作
set users 10 nx ex 122、java代码


三、uuid防止误删锁操作
问题分析

解决
设置不同的uuid,释放锁定的时候判断当前的uuid和要释放的锁uuid是否一样
上面代码修改
设置uuid

比较释放

四、lua保证删除操作原子性



![]()


边栏推荐
- 目标检测和边界框
- 预测销售XGBoost
- MongoDB的使用
- The best storage scheme of MCU CS Chuangshi SD NAND
- Double index mechanism of redis source code analysis
- A set of Jenkins style for personal use
- 修改滚动条样式
- Flink entry to practice - phase I (cluster installation & use)
- JS array intersection, subtraction and union
- Flowable query, complete, void, delete tasks
猜你喜欢

京东购买意向预测(三)

The best storage scheme of MCU CS Chuangshi SD NAND

Flink entry to practice - phase I (cluster installation & use)

How to choose flash for new products?

FMC sub card: 4-channel 250msps sampling rate 16 bit AD acquisition sub card

How does continuous integration manage Jenkins?

MongoDB 索引

会话技术【黑马入门系列】

175. Combine two tables (MySQL database connection)

三伏天逛逛北京动物园
随机推荐
SCI论文的Highlights怎么写(正经的教你怎么写)
导出文件or下载文件
@How can conditionalonmissingbean cover beans in third-party components
175. Combine two tables (MySQL database connection)
Development board training: multi task program under stm32
Understanding of v2x test series v2x phase II application scenario
1669. 合并两个链表(两个链表的合并)
Basic lighting knowledge of shader introduction
Practical tutorial: application of canoe in CAN bus test
A set of Jenkins style for personal use
FMC sub card: 8-channel 125msps sampling rate 16 bit AD acquisition sub card
网站APP数据库里的用户信息被泄露篡改怎么办
fiddler 抓包工具使用
Flink introduction to practice - phase II (illustrated runtime architecture)
【MySQL】 MVCC:正确理解MVCC及其实现原理
Beijing Jiewen technology, an acquiring outsourcing service provider, transferred 60% of its shares for about 480million
Pytorch随记(2)
Use of mongodb
Where is the future of HMI conceptual design?
Pytorch随记(1)