One, Redis is a support transaction, please see this introduction.
Here are a few of the commands that Ruby implements, Multi,exec,discard,watch,unwatch.
1,multi: Mark a transaction block start, exec: Execute all multi after the command issued
Require'Redis'R=Redis.newr.set'a', 1R.set'b', 2R.multir.set'a', 3R.set'b', 6R.exec#r.get ' a '#= "3"#r.get ' B '#= "6"
2,discard: Discard all MULTI post-order commands
Require'Redis'R=Redis.newr.set'a', 1R.set'b', 2R.multir.set'a', 3R.set'b', 6R.discard#r.get ' a '#= "1"#r.get ' B '#= "2"
3,watch: Lock key until the multi/exec command is executed
Watch checks for the given key, if from the start of watch, to exec. When the key being monitored changes, the entire transaction fails.
Assume that two Redis links are R1 and R2, respectively.
Require'Redis'R1=Redis.newr1.set'a', 1R1.set'b', 2R1.multir1.set'a', 3R1.set'b', 6#after changing the value of a in R2, exec executesR1.exec#r1.get ' a '#= "1"#r1.get ' B '#= "2"
' Redis ' ='a', 100
4,unwatch:
Refreshes all keys that have been monitored in a transaction. Start watch again.
The difference between transactions in Redis and transactions in MySQL
When an error occurs in a transaction, the operation in the entire transaction is not rolled back
Redis Ruby Client Learning (v)