配置
<!-- 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已经变回了字符串格式。