zoukankan      html  css  js  c++  java
  • 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已经变回了字符串格式。

  • 相关阅读:
    poj 3669 Meteor Shower
    poj 3009 Curling 2.0
    poj 1979 Red and Black
    区间内素数的筛选
    九度oj 题目1347:孤岛连通工程
    poj 3723 Conscription
    poj 3255 Roadblocks
    Luogu P3975 [TJOI2015]弦论
    AT2165 Median Pyramid Hard 二分答案 脑洞题
    后缀自动机多图详解(代码实现)
  • 原文地址:https://www.cnblogs.com/grey-wolf/p/7910232.html
Copyright © 2011-2022 走看看