当前位置:网站首页>14_Redis_乐观锁
14_Redis_乐观锁
2022-07-02 12:00:00 【听*雨声】
乐观锁
监控:Watch
悲观锁:
- 很悲观,认为什么时候都会出问题,无论做什么都会加锁!
乐观锁:
- 很乐观,认为什么时候都不会出问题,所以不会上锁!更新数据的时候去判断一下,在此期间是否有人修改过这个数据,version !
- 获取version
- 更新的时候比较version
Redis的监视测试
正常执行成功
127.0.0.1:6379> set money 100
OK
127.0.0.1:6379> set out 0
OK
127.0.0.1:6379> watch money // 监视 money对象 ,一旦事务执行成功监控就会取消
OK
127.0.0.1:6379> multi // 事务正常结束,数据期间没有发生变动,这个时候就正常执行成功!
OK
127.0.0.1:6379(TX)> decrby money 20
QUEUED
127.0.0.1:6379(TX)> INCRby out 20
QUEUED
127.0.0.1:6379(TX)> exec
1 ) (integer) 80
2 ) (integer) 20
测试多线程修改值,使用watch可以当做redis的乐观锁操作!

修改方式:释放乐观锁后重新获取乐观锁
1.事务执行失败,就先解锁
获取最新的值,再次监视,select version


边栏推荐
- 17_Redis_Redis发布订阅
- [QNX hypervisor 2.2 user manual]6.3 communication between guest and external
- CDN 在游戏领域的应用
- Edit the formula with MathType, and set it to include only mathjax syntax when copying and pasting
- vChain: Enabling Verifiable Boolean Range Queries over Blockchain Databases(sigmod‘2019)
- 华为面试题: 没有回文串
- Table responsive layout tips
- 02_线性表_顺序表
- C语言习题---(数组)
- Mfc a dialog calls B dialog function and passes parameters
猜你喜欢

GeoServer offline map service construction and layer Publishing

08_ 串

你不知道的Set集合

Base64 编码原来还可以这么理解

Practice of compiling principle course -- implementing an interpreter or compiler of elementary function operation language

04_ 栈

kibana 基础操作

Full of knowledge points, how to use JMeter to generate encrypted data and write it to the database? Don't collect it quickly

Learn the method code example of converting timestamp to uppercase date using PHP

IE 浏览器正式退休
随机推荐
[untitled] leetcode 2321 Maximum score of concatenated array
Some Chinese character codes in the user privacy agreement are not standardized, which leads to the display of garbled codes on the web page. It needs to be found and handled uniformly
2021-2022學年編譯原理考試重點[華僑大學]
【NOI模拟赛】伊莉斯elis(贪心,模拟)
【C语音】详解指针进阶和注意点(2)
【NOI模拟赛】刮痧(动态规划)
TiDB混合部署拓扑
为什么只会编程的程序员无法成为优秀的开发者?
Edit the formula with MathType, and set it to include only mathjax syntax when copying and pasting
关于网页中的文本选择以及统计选中文本长度
编译原理课程实践——实现一个初等函数运算语言的解释器或编译器
Record an interview
Record an error report, solve the experience, rely on repetition
About text selection in web pages and counting the length of selected text
C语言中的算术运算及相关练习题
Kibana basic operation
PHP method to get the index value of the array item with the largest key value in the array
The past and present lives of visual page building tools
华为面试题: 没有回文串
TiDB 软件和硬件环境建议配置