Redis设置HashKey序列化

master
RuoYi 4 years ago
parent cf6254a8d5
commit 4aabf5d8be
  1. 7
      ruoyi-framework/src/main/java/com/ruoyi/framework/config/RedisConfig.java

@ -36,9 +36,14 @@ public class RedisConfig extends CachingConfigurerSupport
mapper.activateDefaultTyping(LaissezFaireSubTypeValidator.instance, ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
serializer.setObjectMapper(mapper);
template.setValueSerializer(serializer);
// 使用StringRedisSerializer来序列化和反序列化redis的key值
template.setKeySerializer(new StringRedisSerializer());
template.setValueSerializer(serializer);
// Hash的key也采用StringRedisSerializer的序列化方式
template.setHashKeySerializer(new StringRedisSerializer());
template.setHashValueSerializer(serializer);
template.afterPropertiesSet();
return template;
}

Loading…
Cancel
Save