当前位置:网站首页>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 CString to char*
- Apprendre le Code de la méthode de conversion du calendrier lunaire grégorien en utilisant PHP
- 2021-2022學年編譯原理考試重點[華僑大學]
- 可视化搭建页面工具的前世今生
- CDN 在游戏领域的应用
- 04_ 栈
- [untitled] leetcode 2321 Maximum score of concatenated array
- TiDB跨数据中心部署拓扑
- 原则、语言、编译、解释
- Why can't programmers who can only program become excellent developers?
猜你喜欢

vChain: Enabling Verifiable Boolean Range Queries over Blockchain Databases(sigmod‘2019)

17_Redis_Redis发布订阅
![[untitled] leetcode 2321 Maximum score of concatenated array](/img/a3/54d0e83f02ef0d0d8d269351c35b39.png)
[untitled] leetcode 2321 Maximum score of concatenated array

CodeCraft-22 and Codeforces Round #795 (Div. 2)D,E

表格响应式布局小技巧

20_Redis_哨兵模式

Internet Explorer officially retired

搭载TI AM62x处理器,飞凌FET6254-C核心板首发上市!

19_Redis_宕机后手动配置主机

Map introduction
随机推荐
How to solve the problem of database content output
10_Redis_geospatial_命令
TiDB数据迁移场景综述
c语言入门--数组
Recommended configuration of tidb software and hardware environment
IE 浏览器正式退休
传感器数据怎么写入电脑数据库
List set & UML diagram
Principles, language, compilation, interpretation
04_ 栈
CodeCraft-22 and Codeforces Round #795 (Div. 2)D,E
How to write sensor data into computer database
05_ queue
HUSTPC2022
C#延时、在线程中开启定时器、获取系统时间
C RichTextBox controls the maximum number of lines displayed
Map介绍
MFC 定时器使用
Internet Explorer officially retired
Dragonfly low code security tool platform development path