The Redis data types are described in the previous chapter, where the transaction issues
NoSQL does not support transactions, although Redis's transactions provides not strictly acid-like transactions (such as a string of exec
Commit the execution of the command, in the execution of the server down, then there will be a part of the command execution, the rest is not executed),
However, this transactions provides the basic command package execution function (in case the server does not have a problem,
You can ensure that a series of commands are executed in sequence, with other client commands inserted in the middle to execute them.
Redis also provides a watch function that allows you to watch a key and then execute transactions,
In this process, if the value of the watched is modified, the transactions will find and refuse to execute.
Session1 (1) 1th Step Redis127.0.0.1:6379>Get Age"Ten"Redis127.0.0.1:6379>Watch age OK Redis127.0.0.1:6379>Multi OK Redis127.0.0.1:6379>Session2 (2) 2nd Step Redis127.0.0.1:6379>SetAge -OK Redis127.0.0.1:6379>Get Age" -"Redis127.0.0.1:6379>Session1 (3) 3rd Step Redis127.0.0.1:6379>SetAge -QUEUED Redis127.0.0.1:6379>exec (nil) Redis127.0.0.1:6379>Get Age" -"Redis127.0.0.1:6379>first step, Session1Haven't had time to modify the value of age the second step, Session2The value of age has been set to 30 third step, Session1You want to set the value of age to 20, but the result of the execution return is nil, stating that execution failed, and then we take the age value is 30, which is due to the optimistic lock on age in Session 1.
Redis Transaction Support