当前位置:网站首页>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 .
边栏推荐
- Is it safe for flush to register and open an account? Is there any risk?
- Flex & bison start
- Mathematical modeling of war preparation 30 regression analysis 2
- 备战数学建模32-相关性分析2
- Get the intersection union difference set of two dataframes
- R language GLM function logistic regression model, using epidisplay package logistic The display function obtains the summary statistical information of the model (initial and adjusted odds ratio and
- Pytoch deep learning code skills
- Use abp Zero builds a third-party login module (I): Principles
- Excerpt from three body
- cluster addslots建立集群
猜你喜欢
随机推荐
The DOTPLOT function in the epidisplay package of R language visualizes the frequency of data points in different intervals in the form of point graphs, specifies the grouping parameters with the by p
Sharing ideas for a quick switch to an underlying implementation
Numpy basic use
Is it safe to open a stock account through the account opening link given by the broker manager? I want to open an account
挖财注册开户安全吗,有没有什么风险?
Introduction to basic knowledge of C language (Daquan) [suggestions collection]
R language GLM function logistic regression model, using epidisplay package logistic The display function obtains the summary statistical information of the model (initial and adjusted odds ratio and
TCP拥塞控制详解 | 1. 概述
Atcoder 238
Where do people get their top energy?
R语言glm函数逻辑回归模型、使用epiDisplay包logistic.display函数获取模型汇总统计信息(自变量初始和调整后的优势比及置信区间,回归系数的Wald检验的p值)、结果保存到csv
R语言dplyr包summarise_at函数计算dataframe数据中多个数据列(通过向量指定)的均值和中位数、指定na.rm参数配置删除缺失值
10分钟了解BIM+GIS融合,常见BIM数据格式及特性
券商经理给的开户链接安全吗?找谁可以开户啊?
R语言使用ggplot2可视化泊松回归模型(Poisson Regression)的结果、可视化不同参量组合下的计数结果
Minister of investment of Indonesia: Hon Hai is considering establishing electric bus system and urban Internet of things in its new capital
Excel-vba quick start (II. Condition judgment and circulation)
Notes on writing questions in C language -- table tennis competition
How to mount cloud disks in ECS
Halcon C # sets the form font and adaptively displays pictures








