自学内容网 自学内容网

Redis-事务-基本操作-在执行阶段出错不会回滚

1、Redis事务控制命令

127.0.0.1:6379> keys *
(empty array)
127.0.0.1:6379> multi
OK
127.0.0.1:6379(TX)> set a1 v1
QUEUED
127.0.0.1:6379(TX)> set a2 v2
QUEUED
127.0.0.1:6379(TX)> set a3 v3
QUEUED
127.0.0.1:6379(TX)> exec
1) OK
2) OK
3) OK
127.0.0.1:6379> keys *
1) "a2"
2) "a1"
3) "a3"
127.0.0.1:6379> 

2、Redis事务错误处理

127.0.0.1:6379> keys *
1) "a2"
2) "a1"
3) "a3"
127.0.0.1:6379> multi
OK
127.0.0.1:6379(TX)> set a4 v4
QUEUED
127.0.0.1:6379(TX)> set a5
(error) ERR wrong number of arguments for 'set' command
127.0.0.1:6379(TX)> set a6 v6
QUEUED
127.0.0.1:6379(TX)> exec
(error) EXECABORT Transaction discarded because of previous errors.
127.0.0.1:6379> keys *
1) "a2"
2) "a1"
3) "a3"
127.0.0.1:6379> 

3、Redis事务错误处理,在执行阶段出错不会回滚

127.0.0.1:6379> keys *
1) "a2"
2) "a1"
3) "a3"
127.0.0.1:6379> multi
OK
127.0.0.1:6379(TX)> set a4 v4
QUEUED
127.0.0.1:6379(TX)> incr a4
QUEUED
127.0.0.1:6379(TX)> set a5 v5
QUEUED
127.0.0.1:6379(TX)> exec
1) OK
2) (error) ERR value is not an integer or out of range
3) OK
127.0.0.1:6379> keys *
1) "a1"
2) "a4"
3) "a2"
4) "a5"
5) "a3"
127.0.0.1:6379> get a4
"v4"
127.0.0.1:6379> 

在这里插入图片描述


原文地址:https://blog.csdn.net/m0_65152767/article/details/139865947

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!