当前位置:网站首页>Redisson分布式锁流程详解(二)
Redisson分布式锁流程详解(二)
2022-07-26 11:46:00 【用户9919783】
Redis分布式锁,有互斥性,容错率,唯一性,防止死锁,这些特点上篇文章都已经介绍过,而且有代码实例,有不明白的地方可以先看看:
下面画了一张流程图,方便大家解读:
从图上可以知道,多个线程获取锁,线程一获取锁成功的话,线程二就会加锁失败,之后重复获取锁,直到线程一释放锁。
若redis是集群部署,线程一加锁成功之后,会用hash算法,选择其中一台redis主机,采用lua脚本,吧数据写入redis,因为锁都会设置一个自动释放时间,这时候会有一个water dog每隔10s监测一次,若业务一直在运行,则会延长当前线程获取锁的时间。
为什么要用lua脚本呢?
因为这里的业务逻辑相当复杂,通过封装在lua脚本发送给redis,还可以保证redis原子性。
Watch dog自动延迟机制?
客户端默认加锁是30s,超过30s,业务还没处理完的情况下,看门狗的作用就体现出来了,每隔10s监测当前线程是否还持有锁,若还在的话就延迟持有时间。
Lua脚本的简介:
KEYS[1]代表的是加锁的key,比如:RLock lock = redissonClient.getLock("lock");
KEYS[1]代表就是lock。
ARGV[1]代表的就是锁默认生存时间,默认30秒
ARGV[2]代表的是加锁的客户端的ID。
边栏推荐
- Miccai2022 paper | evolutionary multi-objective architecture search framework: application in covid-19 3D CT classification
- 如何使用数据管道实现测试现代化
- 元宇宙日报|元宇宙社交 App“派对岛”产品下架;广州南沙元宇宙产业集聚区揭牌;数字经济发展部际联席会议制度推出
- win10使用nvm安装node、npm、cnpm
- Flink 在 讯飞 AI 营销业务的实时数据分析实践
- Live broadcast preview at 19:30 on July 27: harmonyos3 and Huawei's full scene new product launch
- Database composition trigger
- 【通信原理】第三章 -- 随机过程[上]
- 大佬们,cdc oracle 怎么设置从指定scn号开始读取,或是怎么设置只读全量的归档,不去读取快
- Subject 3 turns and turns
猜你喜欢

Test cases should never be used casually, recording the thinking caused by the exception of a test case

Hou Peixin, chairman of the openharmony Working Committee of the open atom open source foundation, sent a message to the openatom openharmony sub forum

Exploration on cache design optimization of community like business

开放原子开源基金会OpenHarmony工作委员会主席侯培新寄语OpenAtom OpenHarmony分论坛

如何使用数据管道实现测试现代化

种种迹象表明,Apple将有望支持AV1

基于 Flink CDC 实现海量数据的实时同步和转换

Substance Painter 2021软件安装包下载及安装教程

System call capture and analysis - modify kernel methods to add system calls

MICCAI2022论文 | 进化多目标架构搜索框架:在COVID-19三维CT分类中的应用
随机推荐
Koin
【通信原理】第二章 -- 确知信号
按位与怎么写SQL
Server memory failure prediction can actually do this!
7月27日19:30直播预告:HarmonyOS3及华为全场景新品发布会
【安徽大学】考研初试复试资料分享
Leetcode / Scala - sum of two numbers, three numbers, four numbers, and N numbers
V01 - XX,记录美好生活从日志开始
元宇宙日报|元宇宙社交 App“派对岛”产品下架;广州南沙元宇宙产业集聚区揭牌;数字经济发展部际联席会议制度推出
Hou Peixin, chairman of the openharmony Working Committee of the open atom open source foundation, sent a message to the openatom openharmony sub forum
Outsourcing for four years, abandoned
哈希表
Live broadcast preview at 19:30 on July 27: harmonyos3 and Huawei's full scene new product launch
向日葵资深产品总监技术分享:如何在AD域环境下应用
Who is responsible for the problems of virtual idol endorsement products? And listen to the lawyer's analysis
忆凤姐
种种迹象表明,Apple将有望支持AV1
Database composition trigger
。。。。。。
pytest接口自动化测试框架 | 使用装饰器修饰需要运行的用例