码迷,mamicode.com
首页 > 其他好文 > 详细

Redis事务

时间:2020-07-28 22:18:34      阅读:70      评论:0      收藏:0      [点我收藏+]

标签:size   没有   role   命令执行   防止   csharp   顺序   err   div   

Redis事务

  Redis事务是一个单独的隔离操作,事务中所有的命令都会序列化、按顺序执行,事务在执行的过程中不会被其它客户端发送过来的命令所打断.

  Redis同一事务中如果有一条命令执行失败,其它的命令仍然会被执行,没有回滚.

  Redis事务的主要作用是串联多个命令,防止别的命令插队.  

 

127.0.0.1:6379> multi 
OK
127.0.0.1:6379> hincrby role role:9527:age 2
QUEUED
127.0.0.1:6379> hincrby role role:9527:age 3
QUEUED
127.0.0.1:6379> hincrby role role:9527:age -5
QUEUED
127.0.0.1:6379> exec
1) (integer) 24
2) (integer) 27
3) (integer) 22
127.0.0.1:6379> multi
OK
127.0.0.1:6379> hmset role role:9527:birthday 1992-10-10 
QUEUED
127.0.0.1:6379> hexists role role:9527:id
QUEUED
127.0.0.1:6379> hkeys role
QUEUED
127.0.0.1:6379> discard
OK
127.0.0.1:6379> multi
OK
127.0.0.1:6379> hkeys role
QUEUED
127.0.0.1:6379> hvals role
QUEUED
127.0.0.1:6379> hincrby role role:9527:name 3
QUEUED
127.0.0.1:6379> exec
1) 1) "role:9527:id"
   2) "role:9527:name"
   3) "role:9527:age"
2) 1) "9527"
   2) "xiaomaomao"
   3) "22"
3) (error) ERR hash value is not an integer
127.0.0.1:6379> multi 
OK
127.0.0.1:6379> hexists role role:9527:name
QUEUED
127.0.0.1:6379> hget role
(error) ERR wrong number of arguments for ‘hget‘ command
127.0.0.1:6379> hsetnx role role:9527:gender female
QUEUED
127.0.0.1:6379> exec
(error) EXECABORT Transaction discarded because of previous errors.

  

  

 

 

Redis事务

标签:size   没有   role   命令执行   防止   csharp   顺序   err   div   

原文地址:https://www.cnblogs.com/xiaomaomao/p/13393411.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!