In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "the detailed explanation of Redis transaction processing". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor to take you to learn the "Redis transaction details" bar!
Transaction processing.
127.0.0.1 purl 6379 > get age
"30"
127.0.0.1 purl 6379 > multi
OK
127.0.0.1 6379 > set age 10
QUEUED
127.0.0.1 6379 > set age 20
QUEUED
127.0.0.1 purl 6379 > exec
1) OK
2) OK
127.0.0.1 purl 6379 > get age
"20"
How to cancel a transaction.
127.0.0.1 purl 6379 > multi
OK
127.0.0.1 6379 > set age 30
QUEUED
127.0.0.1 6379 > set age 40
QUEUED
127.0.0.1 purl 6379 > discard
OK
127.0.0.1 purl 6379 > get age
"20"
Optimistic lock complex transaction control.
Redis optimistic lock example: suppose there is a key of age, and open 2 session to assign age.
Step 1: session1
127.0.0.1 purl 6379 > get age
"20"
127.0.0.1 purl 6379 > watch age
OK
127.0.0.1 purl 6379 > multi
OK
127.0.0.1purl 6379 >
Step 2: session2
127.0.0.1 6379 > set age 30
OK
127.0.0.1 purl 6379 > get age
"30"
127.0.0.1purl 6379 >
Step 3: session1
127.0.0.1 6379 > set age 20
QUEUED
127.0.0.1 purl 6379 > exec
(nil)
127.0.0.1 purl 6379 > get age
"30"
The watch command monitors a given key, and if the monitored key changes since calling watch during exec, the entire transaction will fail, or you can call watch to monitor multiple key multiple times. This allows you to add an optimistic lock to the specified key. Note that the key of watch is valid for the entire connection, as is the transaction. If the connection is disconnected, both monitoring and transactions are automatically cleared. Except for the exec,discard,unwatch command, of course, all monitoring in the connection is cleared.
Transaction rollback: if one command in the transaction fails, the other commands are not rolled back.
127.0.0.1 purl 6379 > get age
"30"
127.0.0.1 purl 6379 > get name
"master"
127.0.0.1 purl 6379 > multi
OK
127.0.0.1 purl 6379 > incr age
QUEUED
127.0.0.1 purl 6379 > incr name
QUEUED
127.0.0.1 purl 6379 > exec
1) (integer) 31
2) (error) ERR value is not an integer or out of range
127.0.0.1 purl 6379 > get age
"31"
127.0.0.1 purl 6379 > get name
"master"
At this point, I believe you have a deeper understanding of the "detailed explanation of Redis transaction processing". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.