RedisExpendUtil.java
/**
* pipeline批量执行redis命令
* @param zSetMap
* @return
*/
public List<Object> zSetPipelineBatchAdd(Map<String, Map<Object, Double>> zSetMap) {
return redisTemplate.executePipelined(new RedisCallback<String>() {
//序列化方式
RedisSerializer keySerializer = redisTemplate.getKeySerializer();
RedisSerializer valueSerializer = redisTemplate.getValueSerializer();
@Override
public String doInRedis(RedisConnection redisConnection) throws DataAccessException {
for (String key : zSetMap.keySet()) {
//value集合
Map<Object, Double> valueScoreMap = zSetMap.get(key);
Set<RedisZSetCommands.Tuple> rawTuples = new LinkedHashSet<>(valueScoreMap.size());
valueScoreMap.forEach((k, v) -> rawTuples.add(new DefaultTuple(valueSerializer.serialize(k), v)));
redisConnection.zAdd(keySerializer.serialize(key), rawTuples);
}
return null;
}
}, redisTemplate.getValueSerializer());
}