BUG代码场景:
String key ="ceshi1";
String newValue = "6";
String oldValue = "7";
//这里是能取到值的
String s = redisOperator.get(key);
System.out.println(s);
SessionCallback<List<Object>> sessionCallback = new SessionCallback() {
@Override
public List<Object> execute(RedisOperations operations) throws DataAccessException {
operations.multi();
String redisValue = (String)operations.opsForValue().get(key);
//这里没有获取到值。
System.out.println(redisValue + "--"+ oldValue);
if(Objects.equals(redisValue, oldValue) || Objects.isNull(redisValue)){
System.out.println( " in set");
operations.opsForValue().set(key, newValue);
}
return operations.exec();
}
};
List<Object> execute = redisOperator.execute(sessionCallback);
System.out.println(JsonUtil.toJson(execute));
追踪到源码时:因为开启了事务,所以 会进入如下所示,return null; 如果是没有开启事务,就会有值。
解决方案:
暂时没有想到 好的方式:等我想到了在来 补充!
补充,目前想到的是 通过自己写 lua脚本 去实现,lua脚本的方式 没有代码写起来那么方便。