当前位置:网站首页>Redis: redis transactions
Redis: redis transactions
2022-07-04 23:06:00 【dengfengling999】


Redis The transaction allows a set of commands to be executed in a single step , And it can ensure that all commands in a transaction are serialized , Then execute in order ; In a Redis Transaction ,Redis Or execute all the commands in it , Or nothing . namely Redis Transactions should be able to ensure serialization and atomicity .
Redis Transactions of can only maintain partial atomicity , Cannot remain completely atomic , Data may be inconsistent
Redis Simplify things , Why simplify ? It should improve its access efficiency , It does not consider the portability of so many transactions
- Redis Common commands for transactions :
- multi
grammar :multi
function : Used to mark the beginning of a transaction block .Redis The subsequent commands will be put into the queue one by one , And then you can use it EXEC The command executes the command sequence atomically .
Return value : Open successfully and return OK

for example :

2.exec
grammar :exec
function : Execute all previously queued commands in a transaction , Then restore the normal connection state .
If an error is reported in the process of pushing the command into the queue , Then the commands in the whole queue will not be executed , Error in execution result ;
If it's normal in the process of pressing the queue , An error is reported for a command in the execution queue , It will only affect the execution result of this command , Other commands operate normally ;
When using WATCH On command , Only if the monitored key has not been modified ,EXEC Command will execute the command in the transaction ; And once implemented exec command , All the previously added watch All monitoring is cancelled .
Return value : The return value of this command is an array , Each of these elements is the return value of each command in the atomized transaction . When using WATCH On command , If the transaction execution aborts , that EXEC The command will return a Null value .
inc k1 : For numerical type k1 Add one , If it is not numerical, report an error , It will not really execute when pressing the opposite column , So I don't know k1 Is it numerical
for example : Press in the right column to report errors , Do not carry out , Keep atomicity

Press the right column without reporting an error :

3.discard
grammar :discard
function : Clear all previously queued commands in a transaction , And end the transaction .
If used WATCH command , that DISCARD The command will cancel the monitoring of all keys currently connected to the monitoring .
Return value : Clear successfully , return OK.

for example :
4.watch

grammar :watch key [key …]
function : When a transaction needs to be executed conditionally , Use this command to set the given key to be monitored . If monitored key When the value is modified outside this transaction , Then the instructions of the firm will not be executed .Watch The command is equivalent to an optimistic lock in a relational database .
Return value : Monitoring successful , return OK.
decrby: Minus the specified value incrby: Add the specified value 
for example :

Establish another connection to make changes vcersion



5.unwatch
grammar :unwatch
function : Clear all previously monitored keys for a transaction .
If in watch After the command, you call EXEC or DISCARD command , So you don't have to call it manually UNWATCH command .
Return value : Clear successfully , return OK.

for example : Clear all monitored

change version:

Redis Business summary :
1、 Separate isolation operation : All commands in the transaction are serialized 、 Execute in sequence . The transaction is in progress , Will not be interrupted by command requests from other clients , Unless used watch Commands monitor certain keys .
2、 The atomicity of transactions is not guaranteed :redis If a command fails in the same transaction , Subsequent orders may still be executed ,redis The transaction was not rolled back .Redis Function simplification has been carried out inside the system , This ensures faster running speed , because Redis The ability to roll back transactions is not required .
边栏推荐
- Persistence mechanism of redis
- Is Huatai Securities a nationally recognized securities firm? Is it safe to open an account?
- Advanced area a of attack and defense world misc Masters_ good_ idea
- PICT 生成正交测试用例教程
- colResizable. JS auto adjust table width plug-in
- 【图论】拓扑排序
- Google collab trample pit
- 【ODX Studio編輯PDX】-0.2-如何對比Compare兩個PDX/ODX文件
- HMS core machine learning service
- ScriptableObject
猜你喜欢

【机器学习】手写数字识别

Advanced area of attack and defense world misc 3-11

位运算符讲解

A complete tutorial for getting started with redis: getting to know redis for the first time

debug和release的区别

C语言快速解决反转链表

The overview and definition of clusters can be seen at a glance

Redis入门完整教程:Redis Shell

Excel 快捷键-随时补充

A complete tutorial for getting started with redis: hyperloglog
随机推荐
【机器学习】手写数字识别
VIM editor knowledge summary
Notepad++ -- editing skills
攻防世界 MISC 进阶区 can_has_stdio?
String类中的常用方法
Talk about Middleware
Complete tutorial for getting started with redis: bitmaps
debug和release的区别
UML diagram memory skills
Gnawing down the big bone - sorting (II)
字体设计符号组合多功能微信小程序源码
Analysis of environmental encryption technology
Attack and defense world misc advanced area Hong
How to choose a securities company? Is it safe to open an account on your mobile phone
Redis:Redis消息的发布与订阅(了解)
qt绘制网络拓补图(连接数据库,递归函数,无限绘制,可拖动节点)
Attack and defense world misc master advanced zone 001 normal_ png
Redis入门完整教程:客户端通信协议
Redis getting started complete tutorial: publish and subscribe
剑指Offer 68 - II. 二叉树的最近公共祖先