spring data redis template GenericJackson2JsonRedisSerializer的使用

配置

    <!-- 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

 

修改配置为以下后:

<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>

效果:

用redis desktop developer查看:

 

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

 

posted @ 2017-11-28 15:31  三国梦回  阅读(9196)  评论(0编辑  收藏  举报