当前位置:网站首页>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
边栏推荐
- 04_ Stack
- 06_栈和队列转换
- List set & UML diagram
- Mfc a dialog calls B dialog function and passes parameters
- Practice of compiling principle course -- implementing an interpreter or compiler of elementary function operation language
- 学习使用php将时间戳转换为大写日期的方法代码示例
- forEach的错误用法,你都学废了吗
- How does CTO help the business?
- CodeCraft-22 and Codeforces Round #795 (Div. 2)D,E
- How does the computer set up speakers to play microphone sound
猜你喜欢
. Net core logging system
Let your HMI have more advantages. Fet-g2ld-c core board is a good choice
【C语音】详解指针进阶和注意点(2)
Practice of compiling principle course -- implementing an interpreter or compiler of elementary function operation language
04_ 栈
Learn the method code example of converting timestamp to uppercase date using PHP
18_Redis_Redis主从复制&&集群搭建
forEach的错误用法,你都学废了吗
Dragonfly low code security tool platform development path
06_ Stack and queue conversion
随机推荐
Internet Explorer officially retired
原则、语言、编译、解释
[development environment] install the visual studio community 2013 development environment (download the installation package of visual studio community 2013 with update 5 version)
08_ strand
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
记一次报错解决经历依赖重复
How to test tidb with sysbench
MFC 定时器使用
基于RZ/G2L | OK-G2LD-C开发板存储读写速度与网络实测
XML Configuration File
php获取数组中键值最大数组项的索引值的方法
06_栈和队列转换
表格响应式布局小技巧
如何对 TiDB 进行 TPC-C 测试
13_Redis_事务
Base64 coding can be understood this way
Leetcode - Search 2D matrix
學習使用php實現公曆農曆轉換的方法代碼
IE 浏览器正式退休
MFC A对话框调用B对话框函数并传参