Redis Transaction Support

Source: Internet
Author: User

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

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.