当前位置:网站首页>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 .
边栏推荐
- [roommate learned to use Bi report data processing in the time of King glory in one game]
- PS style JS webpage graffiti board plug-in
- [ODX studio edit PDX] - 0.2-how to compare two pdx/odx files of compare
- 攻防世界 MISC 进阶区 3-11
- The solution to the lack of pcntl extension under MAMP, fatal error: call to undefined function pcntl_ signal()
- Wechat official account solves the cache problem of entering from the customized menu
- 头文件重复定义问题解决“C1014错误“
- HMS core machine learning service
- Pagoda 7.9.2 pagoda control panel bypasses mobile phone binding authentication bypasses official authentication
- 【二叉树】节点与其祖先之间的最大差值
猜你喜欢
攻防世界 MISC 进阶区 3-11
Redis introduction complete tutorial: detailed explanation of ordered collection
Redis getting started complete tutorial: publish and subscribe
Redis démarrer le tutoriel complet: Pipeline
cout/cerr/clog的区别
SHP data making 3dfiles white film
Redis入门完整教程:有序集合详解
How to send a reliable request before closing the page
[Jianzhi offer] 6-10 questions
Tweenmax emoticon button JS special effect
随机推荐
微信公众号解决从自定义菜单进入的缓存问题
Redis getting started complete tutorial: Key Management
cout/cerr/clog的区别
Attack and defense world misc master advanced zone 001 normal_ png
Sword finger offer 68 - I. nearest common ancestor of binary search tree
Sobel filter
Redis getting started complete tutorial: publish and subscribe
Create Ca and issue certificate through go language
Analog rocker controlled steering gear
Summary of wechat applet display style knowledge points
UML diagram memory skills
【图论】拓扑排序
【ODX Studio编辑PDX】-0.2-如何对比Compare两个PDX/ODX文件
Redis入门完整教程:发布订阅
Is Huatai Securities a nationally recognized securities firm? Is it safe to open an account?
Detailed explanation of heap sort code
JS 3D explosive fragment image switching JS special effect
Redis入门完整教程:Pipeline
Redis入门完整教程:GEO
实战模拟│JWT 登录认证