Redis-a simple understanding of the watch command

The basic syntax is as follows:

WATCH key [key ...]

The Redis Watch command can be used to monitor one or more keys. Once one of the keys is modified (or deleted), the subsequent transactions will be interrupted and will not be executed.

Monitor a key, the key is modified

Operation example: It Insert picture description here
can be found that after the monitored key is modified, the transaction is not executed, so the value of the key is 1.

Monitor multiple keys, one key is modified

Operation example: It
Insert picture description here
can be found that among the monitored multiple keys, the transaction is not executed after one of the key keys is modified, so the value of key is 3, the value of key1 is still 1, and the value of key2 is still 2.

The monitored key is deleted

Operation example: It
Insert picture description here
can be found that after the monitored key is deleted, the transaction is not executed, and the value of key2 remains unchanged, which is still 2.

Guess you like

Origin blog.csdn.net/weixin_38106322/article/details/108486843