内容简介:`从monitor 日志 可以看到开发中 PHP demo 操作
Redis 测试 Demo
<?php # 原子操作 redis 事务 $redis = new \Redis(); $redis->connect('127.0.0.1', '6379', 3); // 监控key WATCH 事务开启前监控key $redis->WATCH('test_hash'); // 开启事务 $redis->MULTI(); // 事务内执行写操作 $redis->set('test_hash', 2); $redis->set('test_hash', 1); // 提交事务 $redis->exec(); // 回滚事务 // $redis->discard();
redis 事务 需要通过 redis-cli monitor 监控中看到 正常提交流程
`
1544372307.803143 [0 127.0.0.1:37532] "MULTI"
1544372307.803225 [0 127.0.0.1:37532] "WATCH" "test_hash"
1544372308.923998 [0 127.0.0.1:37502] "SET" "test_hash" "2"
1544372312.803550 [0 127.0.0.1:37532] "SET" "test_hash" "1"
1544372312.803566 [0 127.0.0.1:37532] "EXEC"
1544372318.742735 [0 127.0.0.1:37502] "get" "test_hash"
如果事务中 中间监控key 发生变动 就会变成
1544372363.760832 [0 127.0.0.1:37556] "WATCH" "test_hash"
1544372363.760935 [0 127.0.0.1:37556] "MULTI"
1544372366.129051 [0 127.0.0.1:37502] "set" "test_hash" "2"
1544372368.761290 [0 127.0.0.1:37556] "EXEC"
从monitor 日志 可以看到 37556
端口实例监控 test_hash
, 37502
端口实例修改了 test_hash
exec 仍然提交 但中间没有提交
"SET" "test_hash" "2"
"SET" "test_hash" "1"
开发中 PHP demo 操作 exec
返回
成功 :
array(2) {
[0] =>
bool(true)
[1] =>
bool(true)
}
失败 :
bool(false)
还有个小彩蛋 测试了下 将 test_hash
类型改外其他 hash 或 zset 事务提交也会成功, 成功后将test_hash 改成 string 类型了. 这又点霸道了.
测试环境 redis 3.2.12
最后更新于 2018-12-09 16:49:47 并被添加「redis」标签,已有 1 位童鞋阅读过。
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- Java事务解析(事务的基本操作+隔离的等级+事务的四大特性+事务的概念)
- 在云中管理事务,第 1 部分: 事务基础和分布式事务
- Spring事务专题(三)事务的基本概念,Mysql事务处理原理
- 嵌套事务、挂起事务,Spring 是怎样给事务又实现传播特性的?
- 分布式事务中使用RocketMQ的事务消息机制优化事务的处理逻辑
- 数据库事务与事务的隔离级别
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Beginning ARKit for iPhone and iPad
Wallace Wang / Apress / 2018-11-5 / USD 39.99
Explore how to use ARKit to create iOS apps and learn the basics of augmented reality while diving into ARKit specific topics. This book reveals how augmented reality allows you to view the screen on ......一起来看看 《Beginning ARKit for iPhone and iPad》 这本书的介绍吧!