Redis advanced ---- transaction

Source: Internet
Author: User

1. Transactions 1.1 multi and exec commands

Send the multi command to declare the transaction; execute the transaction through Exec

Redis does not support transaction rollback

Redis 127.0.0.1: 6379> set key 1 okredis 127.0.0.1: 6379> set key 2 okredis 127.0.0.1: 6379> sadd key 3 (error) Err operation against a key holding the wrong kind of valueredis 127.0.0.1: 6379> sadd key 3 4 (error) Err operation against a key holding the wrong kind of valueredis 127.0.0.1: 6379> sadd keynew 3 (integer) 1 redis 127.0.0.1: 6379> mutil (error) err Unknown command 'mutil 'redis 127.0.0.1: 6379> multiokredis 127.0.0.1: 6379> set key 3 queuedredis 127.0.0.1: 6379> set keynew 4 queuedredis 127.0.0.1: 6379> exec1) ok2) redis 127.0.0.1: 6379> get key "3" redis 127.0.0.1: 6379> Get keynew "4" redis 127.0.0.1: 6379>

1.2 watch command

Monitors a key value. If it is modified, subsequent transactions are blocked. Only defensive.

 
Redis 127.0.0.1: 6379> set key 1 okredis 127.0.0.1: 6379> watch keyokredis 127.0.0.1: 6379> multiokredis 127.0.0.1: 6379> set key 2 queuedredis 127.0.0.1: 6379> exec1) okredis 127.0.0.1: 6379> get key "2" redis 127.0.0.1: 6379>
Redis 127.0.0.1: 6379> set keywatch 1 okredis 127.0.0.1: 6379> set keywatch 2 okredis 127.0.0.1: 6379> watch keywatchokredis 127.0.0.1: 6379> set keywatch 3 okredis 127.0.0.1: 6379> multiokredis 127.0.0.1: 6379> set keywatch 8 queuedredis 127.0.0.1: 6379> exec (NiL) redis 127.0.0.1: 6379> Get keywatch "3" redis 127.0.0.1: 6379>


Redis advanced ---- transaction

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.