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


边栏推荐
猜你喜欢
随机推荐
学习使用php将时间戳转换为大写日期的方法代码示例
Why can't programmers who can only program become excellent developers?
c语言入门--数组
搭载TI AM62x处理器,飞凌FET6254-C核心板首发上市!
TiDB 环境与系统配置检查
2021-2022学年编译原理考试重点[华侨大学]
Have you learned the wrong usage of foreach
AtCoder Beginner Contest 254
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
20_Redis_哨兵模式
哈夫曼树:(1)输入各字符及其权值(2)构造哈夫曼树(3)进行哈夫曼编码(4)查找HC[i],得到各字符的哈夫曼编码
AtCoder Beginner Contest 254
N皇后问题的解决
C语言习题---(数组)
CDN 在游戏领域的应用
List集合&UML图
MFC CString to char*
08_ 串
vChain: Enabling Verifiable Boolean Range Queries over Blockchain Databases(sigmod‘2019)
C language exercises - (array)









