当前位置:网站首页>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


边栏推荐
猜你喜欢

数据分析思维分析方法和业务知识——业务指标

C#代码审计实战+前置知识

Ad20 cannot select the solution of component packaging in PCB editor

Edit the formula with MathType, and set it to include only mathjax syntax when copying and pasting

18_Redis_Redis主从复制&&集群搭建

Leetcode - Search 2D matrix

Jenkins Pipeline 应用与实践

Wechat applet uses towxml to display formula

Li Chuang EDA learning notes 15: draw border or import border (DXF file)
[email protected]: The platform “win32“ is incompatible with this module."/>info [email protected]: The platform “win32“ is incompatible with this module.
随机推荐
2021-2022学年编译原理考试重点[华侨大学]
Advanced C language (realize simple address book)
Map介绍
记一次报错解决经历依赖重复
btrace-(字节码)动态跟踪工具
Kityformula editor configure font size and spacing
蜻蜓低代码安全工具平台开发之路
Huawei interview question: no palindrome string
C语言中的算术运算及相关练习题
LeetCode - 搜索二维矩阵
Have you learned the wrong usage of foreach
Tidb hybrid deployment topology
Key points of compilation principle examination in 2021-2022 academic year [overseas Chinese University]
Printf function and scanf function in C language
电脑怎么设置扬声器播放麦克风的声音
Solve the problem that El radio group cannot be edited after echo
LeetCode_滑动窗口_中等_395.至少有 K 个重复字符的最长子串
如何用 Sysbench 测试 TiDB
JMeter script parameterization
Learn the method code example of converting timestamp to uppercase date using PHP