Affairs
Ømulti,exec action: Start and end tag of transaction
N executes the multi command, Redis feedback OK indicates the start of the transaction, executes the EXEC command, ends the transaction, and begins the sequential execution of the operation in the transaction.
127.0.0.1:6379[5]> MULTI Ok 127.0.0.1:6379[5]> Set K1 1 QUEUED 127.0.0.1:6379[5]> Set K2 2 QUEUED 127.0.0.1:6379[5]> exec 1) OK 2) OK 127.0.0.1:6379[5]> Get K1 "1" 127.0.0.1:6379[5]> get K2 "2" |
Error Handling
Ø syntax error: Execute the command does not exist or the parameter is not correct, all is the syntax error, only has one error in the transaction, Redis executes the EXEC command, will return directly the error, the correct command also will not be executed.
127.0.0.1:6379[5]> Multi Ok 127.0.0.1:6379[5]> Set name Zhangsan QUEUED 127.0.0.1:6379[5]> SSS age 10 (Error) ERR unknown Command ' SSS ' 127.0.0.1:6379[5]> Set Sex Nan QUEUED 127.0.0.1:6379[5]> exec (Error) Execabort Transaction discarded because of previous errors. 127.0.0.1:6379[5]> Get Name (nil) 127.0.0.1:6379[5]> Get Sex (nil) |
Ø Run Error: This type of error execution is correct, but the corresponding key to the operation is incorrect, it will cause errors found at runtime, but does not affect the execution of other correct commands.
127.0.0.1:6379[5]> Multi Ok 127.0.0.1:6379[5]> Set K 10 QUEUED 127.0.0.1:6379[5]>sadd k//operation strings type data using a hash set command QUEUED 127.0.0.1:6379[5]> Set K 100 QUEUED 127.0.0.1:6379[5]> exec 1) OK 2) (Error) Wrongtype Operation against a key holding the wrong of value 3) OK 127.0.0.1:6379[5]> Get K "100" |
Watch Command
Monitors the specified key, and if the monitored key is modified before the following transaction is executed, the transaction containing the action action on the key is not executed and returned to nil.
127.0.0.1:6379[5]> Get K "20" 127.0.0.1:6379[5]> Set K 30 Ok 127.0.0.1:6379[5]>Watch k Ok 127.0.0.1:6379[5]> Set K 40 Ok 127.0.0.1:6379[5]> Multi Ok 127.0.0.1:6379[5]> Set K 50 QUEUED 127.0.0.1:6379[5]> exec (nil) 127.0.0.1:6379[5]> Get K "40" |
Life Time
Øexpire operation: Set the lifetime of a key, in seconds, after the time Redis will automatically delete it.
127.0.0.1:6379[5]> Set name Zhangsan Ok 127.0.0.1:6379[5]>expire name 10//survival time is 10s (integer) 1 127.0.0.1:6379[5]> TTL name (integer) 6 127.0.0.1:6379[5]> ttl name//ttl command to view remaining lifetimes, remaining seconds (integer) 2 127.0.0.1:6379[5]> TTL name (integer)-2 127.0.0.1:6379[5]> Get Name (nil)//name key has been deleted by Redis |
Øpersist operation: Undo the lifetime of the key and revert to a permanent key.
Ok 127.0.0.1:6379[5]> Set name Lisi Ok 127.0.0.1:6379[5]> Expire name 10 (integer) 1 127.0.0.1:6379[5]>persist Name (integer) 1 127.0.0.1:6379[5]> TTL name (integer)-1 127.0.0.1:6379[5]> Get Name "Lisi" |
Øpexpire action: Sets the lifetime of a key, in milliseconds, and Redis automatically deletes it after the time.
127.0.0.1:6379[5]> Pexpire Name 10000 (integer) 1 127.0.0.1:6379[5]> Pttl name//pttl command to view the remaining lifetime, the number of milliseconds remaining (integer) 7139 127.0.0.1:6379[5]> Pttl Name (integer) 2760 127.0.0.1:6379[5]> Pttl Name (integer)-2 |
More:
Redis one of the big summary: Redis five data types and operations
Redis Summary of the three: Sort command (List | collection | Ordered collection to sort)
Redis Grand Summary of the four: task Queue | Publish/Subscribe Mode
----------------------------Finish----------------------------------