当前位置:网站首页>14_ Redis_ Optimistic lock
14_ Redis_ Optimistic lock
2022-07-02 15:20:00 【Listen to the rain】
Optimism lock
monitor :Watch
Pessimistic locking :
- Very pessimistic , I think it's going to go wrong all the time , Whatever you do, you'll lock it !
Optimism lock :
- Very optimistic. , I don't think anything will go wrong at any time , So it won't lock ! When you update the data, judge , Has anyone modified this data in the meantime ,version !
- obtain version
- When updating, compare version
Redis Monitoring tests for
Normal execution succeeded
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 // monitor money object , Once the transaction is successfully executed, the monitoring will be cancelled
OK
127.0.0.1:6379> multi // The business ended normally , There was no change during the data period , At this time, the normal execution is successful !
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
Testing multithreaded modification values , Use watch Can be regarded as redis Optimistic lock operation of !

Modify the way : Release the optimistic lock and re acquire the optimistic lock
1. Transaction execution failed , Just unlock it first
Get the latest value , Watch again ,select version


边栏推荐
猜你喜欢

C language exercises - (array)
![[untitled] leetcode 2321 Maximum score of concatenated array](/img/a3/54d0e83f02ef0d0d8d269351c35b39.png)
[untitled] leetcode 2321 Maximum score of concatenated array

btrace-(字节码)动态跟踪工具

学习使用php将时间戳转换为大写日期的方法代码示例

XML配置文件

15_Redis_Redis.conf详解

可视化搭建页面工具的前世今生

解决el-radio-group 回显后不能编辑问题

C语言习题---(数组)

vChain: Enabling Verifiable Boolean Range Queries over Blockchain Databases(sigmod‘2019)
随机推荐
Huffman tree: (1) input each character and its weight (2) construct Huffman tree (3) carry out Huffman coding (4) find hc[i], and get the Huffman coding of each character
4. Data splitting of Flink real-time project
2021-2022学年编译原理考试重点[华侨大学]
学习使用php将时间戳转换为大写日期的方法代码示例
Application of CDN in game field
MFC CString 转 char*
AtCoder Beginner Contest 254
871. Minimum refueling times: simple priority queue (heap) greedy question
06_栈和队列转换
18_Redis_Redis主从复制&&集群搭建
HUSTPC2022
Base64 coding can be understood this way
04_ 栈
Key points of compilation principle examination in 2021-2022 academic year [overseas Chinese University]
Tidb environment and system configuration check
TiDB跨数据中心部署拓扑
牛客练习赛101
CDN 在游戏领域的应用
11_Redis_Hyperloglog_命令
Topology architecture of the minimum deployment of tidb cluster