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


边栏推荐
猜你喜欢
随机推荐
MFC 控制台打印,弹出对话框
MFC timer usage
HUSTPC2022
飞凌嵌入式RZ/G2L处理器核心板及开发板上手评测
06_ Stack and queue conversion
Why can't programmers who can only program become excellent developers?
C# 线程传参
16_Redis_Redis持久化
[noi Simulation Competition] scraping (dynamic planning)
forEach的错误用法,你都学废了吗
Huawei interview question: no palindrome string
2021-2022學年編譯原理考試重點[華僑大學]
[noi simulation] Elis (greedy, simulation)
Map介绍
Base64 coding can be understood this way
你不知道的Set集合
TiDB 软件和硬件环境建议配置
LeetCode_ String_ Simple_ 412.Fizz Buzz
[solution] educational codeforces round 82
14_Redis_乐观锁









