public void setRedisHash(Map<String,Map<String,String>> map){
RedisSerializer keySerializer = redisTemplate.getKeySerializer();
RedisSerializer hashKeySerializer = redisTemplate.getHashKeySerializer();
RedisSerializer hashValueSerializer = redisTemplate.getHashValueSerializer();
redisTemplate.executePipelined((RedisCallback<Map>) connection-> {
Iterator<Map.Entry<String, Map<String, String>>> iterator = map.entrySet().iterator();
while(iterator.hasNext()){
Map.Entry<String, Map<String, String>> next = iterator.next();
byte[] variantId = keySerializer.serialize(ONLINE_CATEGORY+next.getKey());
Map<byte[],byte[]> hashes = new LinkedHashMap(next.getValue().size());
Iterator<Map.Entry<String, String>> categoryIterator = next.getValue().entrySet().iterator();
while (categoryIterator.hasNext()){
Map.Entry<String, String> category = categoryIterator.next();
hashes.put(hashKeySerializer.serialize(category.getKey()),hashValueSerializer.serialize(category.getValue()));
}
connection.hMSet(variantId, hashes);
}
return null;
});
}
其中的key,hashkey,hashValue序列化可定制
|