当前位置:网站首页>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
边栏推荐
猜你喜欢
btrace-(字节码)动态跟踪工具
LeetCode 209. 长度最小的子数组
实用调试技巧
【NOI模拟赛】伊莉斯elis(贪心,模拟)
Jenkins Pipeline 应用与实践
电脑怎么设置扬声器播放麦克风的声音
[c voice] explain the advanced pointer and points for attention (2)
The past and present lives of visual page building tools
02_线性表_顺序表
It's no exaggeration to say that this is the most user-friendly basic tutorial of pytest I've ever seen
随机推荐
【C语音】详解指针进阶和注意点(2)
用户隐私协议有些汉字编码不规范导致网页显示乱码,需要统一找出来处理一下
The past and present lives of visual page building tools
03_线性表_链表
LeetCode_字符串_简单_412.Fizz Buzz
Introduction to mathjax (web display of mathematical formulas, vector)
C language exercises - (array)
How to conduct TPC-C test on tidb
Btrace- (bytecode) dynamic tracking tool
How to solve the problem of database content output
C thread transfer parameters
List集合&UML图
C#延时、在线程中开启定时器、获取系统时间
info [email protected]: The platform “win32“ is incompatible with this module.
SQL 后计算的利器 SPL
TiDB跨数据中心部署拓扑
电脑怎么设置扬声器播放麦克风的声音
04_ 栈
kibana 基础操作
20_Redis_哨兵模式