Bladeren bron

Redis设置HashKey序列化

RuoYi 3 jaren geleden
bovenliggende
commit
4aabf5d8be
1 gewijzigde bestanden met toevoegingen van 6 en 1 verwijderingen
  1. 6 1
      ruoyi-framework/src/main/java/com/ruoyi/framework/config/RedisConfig.java

+ 6 - 1
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;
     }