Redis Ruby Client Learning (v)

Source: Internet
Author: User

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)

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.