redistemplate事务实践
来源:互联网 发布:日语翻译精确的软件 编辑:程序博客网 时间:2024/05/20 04:49
code:
public Object testRedisMulti() { Object o = stringRedisTemplate.execute(new SessionCallback() { @Override public Object execute(RedisOperations operations) throws DataAccessException { // operations.watch("testRedisMulti"); operations.multi(); operations.opsForValue().set("testRedisMulti", "0"); String now = (String) operations.opsForValue().get("testRedisMulti"); System.out.println(now); try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } now = (String) operations.opsForValue().get("testRedisMulti"); System.out.println(now); Object rs = operations.exec(); return rs; } }); System.out.println(o); return o; }
初始值:
127.0.0.1:6389> get testRedisMulti
"initial"
代码执行:
operations.multi(); operations.opsForValue().set("testRedisMulti", "0"); String now = (String) operations.opsForValue().get("testRedisMulti"); System.out.println(now); try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); }
客户端:
127.0.0.1:6389> get testRedisMulti
"initial",意味着multi中的命令还未发送
System.out输出:
null
注意在multi中的get是娶不到值的
过5秒。。。
代码执行:
now = (String) operations.opsForValue().get("testRedisMulti"); System.out.println(now); Object rs = operations.exec(); return rs;
System.out输出:
null
客户端:
127.0.0.1:6389> get testRedisMulti
"0",multi命令提交后修改了值
最终输出
[0, 0]
可以看到两次get的值返回给了execute函数,而且是修改后的值,符合原理
隐患?!
Sping Data Redis 使用事务时,不关闭连接的问题
阅读全文
0 0
- redistemplate事务实践
- redistemplate 乐观锁实践
- Spring RedisTemplate操作-事务操作
- 事务脚本实践
- NHibernate实践之----事务
- 分布式事务项目实践
- 分布式事务架构实践
- 深入理解Spring Redis的使用 (二)、RedisTemplate事务支持、序列化
- 深入理解Spring Redis的使用 (二)、RedisTemplate事务支持、序列化
- 本地事务和分布式事务工作实践
- 本地事务和分布式事务工作实践
- 本地事务和分布式事务工作实践
- 本地事务和分布式事务工作实践
- redisTemplate 操作
- RedisTemplate API
- RedisTemplate 分页
- redistemplate api
- RedisTemplate使用
- C++ Opencv 人脸检测
- 定积分的基本性质6 积分第一中值定理
- IDEAJ中Scala打包提交Spark集群运行
- F
- 人工智能之机器学习路线图
- redistemplate事务实践
- 网络通信概述
- Redis介绍与安装
- 第十五周Java作业--线程
- 符号表之二:组织和运营策略
- apt-get基本命令
- 在开发板上实现usb mouse做画笔的功能
- 新建Module作为依赖库后出现“unspecified on project app resolves to an APK archive which……”错误的解决方法
- 不负韶华