Redis Watch multi exec Relationship

Source: Internet
Author: User

Exec

Executes the commands within all the transaction blocks.

If a (or some) key is under watch command monitoring and there are commands related to this (or these) key in the transaction block, then the exec command executes and takes effect only if the (or these) key is not modified by another command. Otherwise the transaction is interrupted (abort).

return value:
The return value of all commands within a transaction block, sorted by the order in which they were executed. Null value returned when the operation is interrupted nil .
# Monitor key, and the transaction executes successfully 127.0.0.1:6379> get key
"111"
127.0.0.1:6379> Watch Key
Ok
127.0.0.1:6379> Multi
Ok
127.0.0.1:6379> Set Key 222
QUEUED
127.0.0.1:6379> exec
1) OK
127.0.0.1:6379> Get key
"222"
127.0.0.1:6379> # Monitor key, and transaction is interrupted 127.0.0.1:6379> set key 222
QUEUED
127.0.0.1:6379> exec
1) OK
127.0.0.1:6379> Get key
"222"
127.0.0.1:6379> Watch Key
Ok
127.0.0.1:6379> Set Key 333
Ok
127.0.0.1:6379> Multi
Ok
127.0.0.1:6379> Set Key 444
QUEUED
127.0.0.1:6379> exec
(nil)

"333"
------------------
Under the same client, as long as the value of key is changed before multi executes after watch, the changed value will be the current key value, and the operation on changing the key value in the transaction will no longer take effect.
Under different clients, for example, perform watch key on a client and then execute multi. At this point, under the B client re-set the key value, and then back to the a client, also reset another set key value, then exec will return to a null value, the final key value is the value set under the B client.
In theory, a client will eventually set the value in the transaction to the final value, but the a client will assume that the value of the B client was executed before multi, and then the a client execution will return empty.



Redis Watch multi exec Relationship

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.