当前位置:网站首页>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
边栏推荐
- 你不知道的Set集合
- 电脑怎么设置扬声器播放麦克风的声音
- Solve the problem that El radio group cannot be edited after echo
- Have you learned the wrong usage of foreach
- C# richTextBox控制显示最大行数
- Introduction to mathjax (web display of mathematical formulas, vector)
- 06_栈和队列转换
- 20_Redis_哨兵模式
- LeetCode - 搜索二维矩阵
- Slashgear shares 2021 life changing technology products, which are somewhat unexpected
猜你喜欢
LeetCode 209. 长度最小的子数组
Dragonfly low code security tool platform development path
04_ 栈
02_线性表_顺序表
Full of knowledge points, how to use JMeter to generate encrypted data and write it to the database? Don't collect it quickly
Ad20 cannot select the solution of component packaging in PCB editor
Fundamentals of software testing
The past and present lives of visual page building tools
[email protected] : The platform “win32“ is incompatible with this module."/>
info [email protected] : The platform “win32“ is incompatible with this module.
数据分析思维分析方法和业务知识——业务指标
随机推荐
TiDB跨数据中心部署拓扑
电脑怎么设置扬声器播放麦克风的声音
Introduction to C language -- array
Sharp tool SPL for post SQL calculation
如何用 Sysbench 测试 TiDB
C# 线程传参
TiDB数据迁移工具概览
【NOI模拟赛】伊莉斯elis(贪心,模拟)
Table responsive layout tips
TiDB 软件和硬件环境建议配置
Tidb data migration scenario overview
C language exercises - (array)
表格响应式布局小技巧
Tidb hybrid deployment topology
03_线性表_链表
[development environment] install the visual studio community 2013 development environment (download the installation package of visual studio community 2013 with update 5 version)
Have you learned the wrong usage of foreach
GeoServer offline map service construction and layer Publishing
学习使用php实现公历农历转换的方法代码
.NET Core 日志系统