如果
`public void test2Trans() {
long start = System.currentTimeMillis();
Transaction tx = jedis.multi();
try{
for (int i = 0; i < 100000; i++) {
tx.set("t" + i, "t" + i);
}
}catch(Exception e){
tx.discard();
}
List results = tx.exec();
long end = System.currentTimeMillis();
System.out.println("Transaction SET: " + ((end - start)/1000.0) + " seconds");
}
`
假设代码在try{}模块出现问题,那么catch{}模块直接取消事务的话.那么如何让这段代码实现rollback;
上面代码是个人猜想.求大神帮忙
出现异常的位置有两种情况:
在exec执行中时,即使出现异常,redis也不会终止和rollback,而是继续执行。
官方这样解释不支持回滚:
Redis is internally simplified and faster because it does not need the ability to roll back.
An argument against Redis point of view is that bugs happen, however it should be noted that in general the roll back does not save you from programming errors. For instance if a query increments a key by 2 instead of 1, or increments the wrong key, there is no way for a rollback mechanism to help. Given that no one can save the programmer from his errors, and that the kind of errors required for a Redis command to fail are unlikely to enter in production, we selected the simpler and faster approach of not supporting roll backs on errors.
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。