婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > Redis緩存-序列化對象存儲亂碼問題的解決

Redis緩存-序列化對象存儲亂碼問題的解決

熱門標簽:十堰營銷電銷機器人哪家便宜 山東外呼銷售系統招商 貴州電銷卡外呼系統 魔獸2青云地圖標注 宿遷便宜外呼系統平臺 北京400電話辦理收費標準 超呼電話機器人 鄭州人工智能電銷機器人系統 日本中國地圖標注

使用Redis緩存對象會出現下圖現象:

鍵值對都是亂碼形式。

解決以上問題:

如果是xml配置的

我們直接注入官方給定的keySerializer,valueSerializer,hashKeySerializer即可:

bean id="apiRedisTemplate" class="org.springframework.data.redis.core.RedisTemplate"
        p:connection-factory-ref="apiCacheRedisConnectionFactory">
        property name="keySerializer">
            bean
                class="org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer" />
        /property>
        property name="valueSerializer">
            bean
                class="org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer" />
        /property>

        property name="hashKeySerializer">
            bean
                class="org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer" />
        /property>
        property name="hashValueSerializer">
            bean
                class="org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer" />
        /property>
        property name="stringSerializer">
            bean
                class="org.springframework.data.redis.serializer.StringRedisSerializer" />
        /property>
    /bean>

spring boot 項目配置RedisConfig的時候使用以下方法:

@Configuration
public class RedisConfig {
    @Bean("jsonRedisTemplate")
    public RedisTemplateObject, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory)
            throws UnknownHostException {
        RedisTemplateObject, Object> template = new RedisTemplateObject, Object>();
        template.setConnectionFactory(redisConnectionFactory);      //解決日期序列化問題
        ObjectMapper om = new ObjectMapper();
        om.setDateFormat(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"));
        GenericJackson2JsonRedisSerializer genericJackson2JsonRedisSerializer = new GenericJackson2JsonRedisSerializer(om);
        template.setDefaultSerializer(genericJackson2JsonRedisSerializer);
        return template;

    }
}

Redis存入中文,取出來是亂碼wenti

默認情況下,用redis存入中文,取出時會出現亂碼情況,如圖:

解決

我們再啟動redis時,可以在redis-cli 后面加上 --raw,如圖

以上為個人經驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

您可能感興趣的文章:
  • Redis如何存儲對象與集合示例詳解
  • 淺談Redis存儲數據類型及存取值方法
  • redis 存儲對象的方法對比分析

標簽:臺州 北京 吉安 楊凌 果洛 江蘇 朝陽 大慶

巨人網絡通訊聲明:本文標題《Redis緩存-序列化對象存儲亂碼問題的解決》,本文關鍵詞  Redis,緩存,序列化,對象,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《Redis緩存-序列化對象存儲亂碼問題的解決》相關的同類信息!
  • 本頁收集關于Redis緩存-序列化對象存儲亂碼問題的解決的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 永和县| 西畴县| 子洲县| 海盐县| 丁青县| 德庆县| 衡阳县| 社旗县| 金门县| 西峡县| 星子县| 泾源县| 精河县| 浦江县| 建始县| 蓬安县| 延边| 津市市| 万安县| 游戏| 临武县| 拉萨市| 海林市| 根河市| 庄浪县| 鄯善县| 土默特右旗| 黄平县| 北流市| 横山县| 塔城市| 阿拉善右旗| 读书| 武城县| 杭州市| 长垣县| 江山市| 瑞金市| 义乌市| 怀宁县| 阿城市|