配置

    <!-- redis template definition -->
    <bean id="myRedisTemplate" class="org.springframework.data.redis.core.RedisTemplate" p:connection-factory-ref="jedisConnectionFactory">
        <property name="defaultSerializer">
            <bean class="org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer"></bean>
        </property>
        
    </bean>

上述配置的后果是:序列化后的key也变成了json

spring data redis template GenericJackson2JsonRedisSerializer的使用

 

修改配置为以下后:

<bean id="myRedisTemplate" class="org.springframework.data.redis.core.RedisTemplate" p:connection-factory-ref="jedisConnectionFactory">
        <property name="defaultSerializer">
            <bean class="org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer"></bean>
        </property>
        <property name="keySerializer">
            <bean class="org.springframework.data.redis.serializer.StringRedisSerializer" />
        </property>
        <property name="hashKeySerializer">
            <bean class="org.springframework.data.redis.serializer.StringRedisSerializer" />
        </property>
    </bean>

效果:

spring data redis template GenericJackson2JsonRedisSerializer的使用

用redis desktop developer查看:

spring data redis template GenericJackson2JsonRedisSerializer的使用

 

key已经变回了字符串格式。

 

相关文章:

  • 2021-12-29
猜你喜欢
  • 2021-06-02
  • 2022-12-23
  • 2022-12-23
  • 2021-12-08
  • 2021-09-12
  • 2021-08-03
相关资源
相似解决方案