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


边栏推荐
猜你喜欢
随机推荐
N皇后问题的解决
16_Redis_Redis持久化
05_ queue
btrace-(字节码)动态跟踪工具
CodeCraft-22 and Codeforces Round #795 (Div. 2)D,E
LeetCode_ String_ Simple_ 412.Fizz Buzz
2021-2022学年编译原理考试重点[华侨大学]
[noi Simulation Competition] scraping (dynamic planning)
學習使用php實現公曆農曆轉換的方法代碼
如何对 TiDB 进行 TPC-C 测试
C#延时、在线程中开启定时器、获取系统时间
使用 TiUP 部署 TiDB 集群
Sharp tool SPL for post SQL calculation
Kibana basic operation
C# 线程传参
Data analysis thinking analysis methods and business knowledge - business indicators
Introduction to C language -- array
About text selection in web pages and counting the length of selected text
21_ Redis_ Analysis of redis cache penetration and avalanche
15_Redis_Redis.conf详解







![[noi Simulation Competition] scraping (dynamic planning)](/img/ee/27a07f80207a2925f5065e633eb39f.png)
![[noi simulation] Elis (greedy, simulation)](/img/a2/f8c8ab3bc8dd779327be3f76990976.png)