当前位置:网站首页>Redis transaction and watch instruction
Redis transaction and watch instruction
2022-06-26 15:00:00 【Hua Weiyun】
Redis Affairs and watch Instructions
Redis Business
redis Our business is MULTI Instructions indicate that things are open , Sent by the client after the service is opened EXEC DISCARD WATCH MULTI The order is executed immediately , Other instructions will be put into the business queue , Then come back and send a message to the client :QUEUE
When the client sends... To the server EXEC Time of instruction , The server traverses the business queue of the client , Carry out all instructions saved , And return all the performance results to the client .
watch Instructions
watch The directive is able to monitor multiple database keys , When excc The time when the order is fulfilled , If the monitored database key has been modified , Failure in business performance , The principle is redis There are in the database watched_keys Dictionaries , Dictionary keys are watch Command supervised database key , Values are linked lists , Record all client information that monitors this key .
When the database modification instruction is executed, it will call touchWatchedKey function ,touchWatchedKey Function will set the client of the correction key CLIENT_DIRTY_CAS identification
// When key Corrected , Call this function void signalModifiedKey(redisDb *db, robj *key) { touchWatchedKey(db,key);}// Touch One key, If we should key Being supervised , Then the client will perform EXEC defeat void touchWatchedKey(redisDb *db, robj *key) { list *clients; listIter li; listNode *ln; // If there is no supervised in the database key, Come straight back if (dictSize(db->watched_keys) == 0) return; // Find out what to supervise key Of client Linked list clients = dictFetchValue(db->watched_keys, key); // Not found back if (!clients) return; /* Mark all the clients watching this key as CLIENT_DIRTY_CAS */ /* Check if we are already watching for this key */ listRewind(clients,&li); // Traverse everything to supervise the key Of client while((ln = listNext(&li))) { client *c = listNodeValue(ln); // Set up CLIENT_DIRTY_CAS identification c->flags |= CLIENT_DIRTY_CAS; }}Then the server receives a message from the client exec When the command , The server depends on the client CLIENT_DIRTY_CAS Identification judgment , If there is this sign , The description has been corrected , The server will reject the business submitted by the client .
summary
This is it. redis Relevant contents of the transaction , The transaction is started through MULTI command , All commands go into the transaction queue , When executed exec When ordered , The commands in the transaction queue are submitted together ,watch Command to monitor keys , When a key is modified during a transaction , The monitor corresponding to this key can detect , Then the transaction will fail to commit , Ensure transaction consistency .
️ Thank you for your
If you think this is helpful for you :
- Welcome to follow me ️, give the thumbs-up , Comment on , forward
- Focus on
Panpan small class, Push good articles for you regularly , There are also group chat and irregular lottery activities , You can say what you want , Communicate with the great gods , Learning together . - If there is anything inappropriate, you are welcome to criticize and correct .
边栏推荐
- 710. random numbers in the blacklist
- 文献1
- 【云原生】 ”人人皆可“ 编程的无代码 iVX 编辑器
- View touch analysis
- Electron
- TS常用数据类型总结
- TCP拥塞控制详解 | 1. 概述
- VMware partial settings
- R language dplyr package summary_ The at function calculates the mean and median of multiple data columns (specified by vectors) in the dataframe data, and specifies na RM parameter configuration dele
- Mark: unity3d cannot select resources in the inspector, that is, project locking
猜你喜欢

TCP拥塞控制详解 | 1. 概述
![[cloud native] codeless IVX editor programmable by](/img/10/7c56e46df69be6be522a477b00ec05.png)
[cloud native] codeless IVX editor programmable by "everyone"

使用 Abp.Zero 搭建第三方登录模块(二):服务端开发

View触摸分析

Get the intersection union difference set of two dataframes

Naacl2022: (code practice) good visual guidance promotes better feature extraction, multimodal named entity recognition (with source code download)

印尼投资部长:鸿海考虑在其新首都建立电动公交系统、城市物联网

人力资源导出数据 excel VBA

Unity uses skybox panoramic shader to make panorama preview. There is a gap. Solution

NAACL2022:(代码实践)好的视觉引导促进更好的特征提取,多模态命名实体识别(附源代码下载)...
随机推荐
Informatics Olympiad all in one 1400: count the number of words (string matching)
Mathematical modeling of war preparation 30 regression analysis 2
Datasets dataset class (2)
打新债注册开户安全吗,有没有什么风险?
One copy ten, CVPR oral was accused of plagiarizing a lot, and it was exposed on the last day of the conference!
Kubernetes的pod调度
Flex & bison start
15 bs对象.节点名称.节点名称.string 获取嵌套节点内容
Understand the difference and use between jsonarray and jsonobject
A remove the underline from the label
Oracle11g database import and export method tutorial [easy to understand]
'coach, I want to play basketball!'—— AI Learning Series booklet for system students
SAP gui 770 下载
Combat readiness mathematical modeling 31 data interpolation and curve fitting 3
feil_uVission4左侧工目录消失
Is it safe to open an online stock account? Somebody give me an answer
Equation derivation: second order active bandpass filter design! (download: Tutorial + schematic + Video + code)
Keil4打开单片机工程一片空白,cpu100%程序卡死的问题解决
fileinput. js php,fileinput
Error when redis is started: could not create server TCP listening socket *: 6379: bind: address already in use - solution