Nosql Redis: transaction processing and operation commands

Source: Internet
Author: User
Multi indicates the start of a transaction, and multiple commands in the transaction block are sequentially put into a queue, and finally executed by exec. time Complexity: O (1) Return Value: total returns OKdiscard to cancel the transaction and discard all commands of the transaction block. if you are using watch monitoring, all monitoring will be canceled. time Complexity: O (1) Return Value: Total Return OKwatch format: wathck

Multi indicates the start of a transaction, and multiple commands in the transaction block are sequentially put into a queue, and finally executed by exec. time Complexity: O (1) Return Value: always return OK discard to cancel the transaction and discard all commands of the transaction block. if you are using watch monitoring, all monitoring will be canceled. time Complexity: O (1) Return Value: Total Return OK watch format: wathc k

Multi
Mark the start of a transaction. Multiple commands in the transaction block are sequentially put into a queue and finally executed by exec.
Time Complexity: O (1)
Return Value: Always Returns OK
Discard
Cancel the transaction and discard all commands of the transaction block. If you are using watch monitoring, all monitoring will be canceled.
Time Complexity: O (1)
Return Value: Always Returns OK

Watch
Format: wathc key [key...]
Specifies the KEY (multiple keys) to be monitored. If this (or these) key is changed by other commands before the transaction is executed, the transaction will be interrupted.
Time Complexity: O (1)
Return Value: Always Returns OK

Exec
Execute all the commands in the transaction block. (note the watch mentioned above ).
Time Complexity:
The sum of time complexity of all commands in the transaction block.
Return Value:
The return values of all commands in the transaction block are arranged in order of command execution.
When the operation is interrupted, the return value is nil.

========================================================== = Normal transactions: # Start a new transaction redis 127.0.0.1: 6379> multiOK # execute a command. It can be seen from the returned results that the command is not executed immediately, but added to the transaction queue. redis 127.0.0.1: 6379> set key_id 2 QUEUED # two identical redis 127.0.0.1: 6379> incr key_idQUEUEDredis 127.0.0.1: 6379> incr key_idQUEUED # submit transaction redis 127.0.0.1: 6379> exec1) OK2) (integer) 33) (integer) 4 ============================================== # monitoring key, successful transaction execution: redis 127.0.0.1: 6379> watch key_idOKredis 127.0.0.1: 6379> multiOKredis 127.0.0.1: 6379> incr 2017127.0.0.1: 6379> incr key_idQUEUEDredis 127.0.0.1: 6379> exec1) (integer) 52) (integer) 6 ================================================ = # monitoring key, and the transaction is interrupted redis 127.0.0.1: 6379> watch key_idOKredis 127.0.0.1: 6379> multiOK # set key_id 10 redis 127.0.0.1 has been executed by another user before this: 6379> set key_id 12 QUEUED # The transaction fails to be executed because the key_id is modified. redis 127.0.0.1: 6379> exec (nil) redis 127.0.0.1: 6379> get key_id "10" ==================================== ========## redis 127.0.0.1 error in the transaction: 6379> multiOKredis 127.0.0.1: 6379> set key_id 14 QUEUEDredis 127.0.0.1: 6379> set nma (error) ERR wrong number of arguments for 'set' command # When an error occurs in redis, no rollback. other commands are still executed as usual. this is also the redis 127.0.0.1: 6379> exec1) OK

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.