springboot自定义的redisTemplate提供了更高级的功能,比如支持序列化和反序列化,支持自定义缓存策略,支持缓存组件,支持灵活的缓存管理等,这些功能都是系统自带的redisTemplate所不具备的,所以可以取代系统自带的redisTemplate。
覆盖啊。你看一下优先级加载
execute
有很多参数
常用的有execute(RedisCallback)
和execute(SessionCallback)
通常都是使用SessionCallback
,因为封装的更好用,不需要自己转byte
在execute
中,你可以在回调中随意获取值,这和executePipelined
有很大区别。
看看两者的区别
redisTemplate.execute(new SessionCallback<Object>() {
@Override
public <K, V> Object execute(RedisOperations<K, V> operations) throws DataAccessException {
operations.watch("监控key");
if ("蛇皮".equals(operations.opsForValue().get("监控key"))){
operations.multi();
operations.delete("监控key");
List<Object> exec = operations.exec();
//这里就可以看到结果
System.out.println(exec);
return exec;
}
operations.unwatch();
return null;
}
});