首先是批量插入方法
redisTemplate.executePipelined(new SessionCallback<Object>() {
@Override
public Object execute(RedisOperations operations) throws DataAccessException {
configInfos.stream().forEach(m -> {
operations.opsForValue().set(RedisConstants.alarm_config_key + m.getDeviceType() + ":" + m.getAlarmCategoryCode(), JSONObject.toJSONString(m));
});
//参数回调必须返回null,否则将抛出异常,可参考源码。
return null;
}
});
然后是批量读取的时候,这里改了好几次,发现必须先全部读出来吗,然后在pipelined的外部进行处理操作,在里面进行操作不生效的。
List list = redisTemplate.executePipelined(
new RedisCallback<String>() {
@Override
public String doInRedis(RedisConnection connection) throws DataAccessException {
for (String key : keys) {
connection.get(redisTemplate.getKeySerializer().serialize(key));
}
return null;
}
}
);