当前位置:网站首页>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 .
边栏推荐
- Install the gold warehouse database of NPC
- 时间 (计算)总工具类 例子: 今年开始时间和今年结束时间等
- Redis入门完整教程:键管理
- A complete tutorial for getting started with redis: hyperloglog
- String类中的常用方法
- [ODX studio edit PDX] - 0.2-how to compare two pdx/odx files of compare
- MariaDB的Galera集群应用场景--数据库多主多活
- 头文件重复定义问题解决“C1014错误“
- Redis入门完整教程:慢查询分析
- Redis入门完整教程:GEO
猜你喜欢
[sword finger offer] questions 1-5
浅聊一下中间件
cout/cerr/clog的区别
Redis:Redis消息的发布与订阅(了解)
Advanced area of attack and defense world misc 3-11
One of the commonly used technical indicators, reading boll Bollinger line indicators
【二叉树】节点与其祖先之间的最大差值
Network namespace
Google Earth engine (GEE) - globfire daily fire data set based on mcd64a1
Analysis of the self increasing and self decreasing of C language function parameters
随机推荐
该如何去选择证券公司,手机上开户安不安全
微信公众号解决从自定义菜单进入的缓存问题
【二叉树】节点与其祖先之间的最大差值
Sword finger offer 68 - ii The nearest common ancestor of binary tree
剑指 Offer 65. 不用加减乘除做加法
Redis入门完整教程:慢查询分析
Wechat official account solves the cache problem of entering from the customized menu
Network namespace
Redis:Redis消息的发布与订阅(了解)
Qt个人学习总结
Photoshop批量给不同的图片添加不同的编号
数据库基础知识
The overview and definition of clusters can be seen at a glance
P2181 对角线和P1030 [NOIP2001 普及组] 求先序排列
Excel 快捷键-随时补充
How can enterprises cross the digital divide? In cloud native 2.0
Google Earth engine (GEE) - globfire daily fire data set based on mcd64a1
攻防世界 MISC 进阶区 3-11
【室友用一局王者荣耀的时间学会了用BI报表数据处理】
实战模拟│JWT 登录认证