最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Redis?key-value亂碼的解決

 更新時間:2022年06月01日 11:17:34   作者:JavaEE_202008  
本文主要介紹了Redis?key-value亂碼的解決,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

redis 配置類

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

@SpringBootConfiguration
public class RedisConfig extends CachingConfigurerSupport {

? ? /**
? ? ?* 注入 RedisConnectionFactory
? ? ?*/
? ? @Autowired
? ? private RedisConnectionFactory redisConnectionFactory;

? ? @Bean
? ? public CacheManager cacheManager(RedisConnectionFactory factory) {
? ? ? ? return RedisCacheManager.builder(factory).build();
? ? }

? ? @Bean
? ? public RedisTemplate<String, Object> functionDomainRedisTemplate() {
? ? ? ? RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
? ? ? ? redisTemplate.setConnectionFactory(redisConnectionFactory);

? ? ? ? // 使用Jackson2JsonRedisSerialize 替換默認序列化
? ? ? ? Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);

? ? ? ? ObjectMapper objectMapper = new ObjectMapper();
? ? ? ? objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
? ? ? ? objectMapper.activateDefaultTyping(objectMapper.getPolymorphicTypeValidator(), ObjectMapper.DefaultTyping.NON_FINAL);
? ? ? ? jackson2JsonRedisSerializer.setObjectMapper(objectMapper);

? ? ? ? // 設(shè)置value的序列化規(guī)則和 key的序列化規(guī)則
? ? ? ? StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
? ? ? ? redisTemplate.setKeySerializer(stringRedisSerializer);
? ? ? ? redisTemplate.setHashKeySerializer(stringRedisSerializer);
? ? ? ? redisTemplate.setValueSerializer(jackson2JsonRedisSerializer);
? ? ? ? redisTemplate.setHashValueSerializer(jackson2JsonRedisSerializer);
? ? ? ? redisTemplate.afterPropertiesSet();
? ? ? ? return redisTemplate;
? ? }

}

當使用opsForValue() 存取String類型key,value情形

    @Autowired
    private StringRedisTemplate redisTemplate;

當使用opsForValue() 存取String類型key,自定義對象value情形

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

當使用hash結(jié)構(gòu)時

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;
BoundHashOperations<String, Object, Object> ops = redisTemplate.boundHashOps("key1");
        ops.put("key2",obj);

到此這篇關(guān)于Redis key-value亂碼的解決的文章就介紹到這了,更多相關(guān)Redis key-value亂碼內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 解讀緩存db redis local的取舍之道

    解讀緩存db redis local的取舍之道

    這篇文章主要介紹了解讀緩存db redis local的取舍之道,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-05-05
  • Linux Redis 的安裝步驟詳解

    Linux Redis 的安裝步驟詳解

    這篇文章主要介紹了 Linux Redis 的安裝步驟詳解的相關(guān)資料,希望大家通過本文能掌握如何安裝Redis,需要的朋友可以參考下
    2017-08-08
  • 詳解如何在YAML文件中配置Redis

    詳解如何在YAML文件中配置Redis

    在現(xiàn)代軟件開發(fā)中,配置文件是非常重要的一部分,其中,YAML(YAML Ain't Markup Language)是一種常用的配置文件格式,具有可讀性強、易于理解和編寫的特點,在本篇文章中,我們將探討如何在YAML文件中配置Redis,需要的朋友可以參考下
    2024-09-09
  • Redis如何統(tǒng)計用戶訪問量

    Redis如何統(tǒng)計用戶訪問量

    這篇文章主要介紹了Redis如何統(tǒng)計用戶訪問量問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-07-07
  • Redis超詳細講解高可用主從復(fù)制基礎(chǔ)與哨兵模式方案

    Redis超詳細講解高可用主從復(fù)制基礎(chǔ)與哨兵模式方案

    Redis因為其高性能和易用性在我們后端的服務(wù)中發(fā)揮了巨大的作用,并且很多重要功能的實現(xiàn)都會依賴redis,本篇我們來了解Redis高可用主從復(fù)制與哨兵模式
    2022-04-04
  • Redis 實現(xiàn)隊列原理的實例詳解

    Redis 實現(xiàn)隊列原理的實例詳解

    這篇文章主要介紹了Redis 實現(xiàn)隊列原理的實例詳解的相關(guān)資料,希望通過本文能幫助到大家,需要的朋友可以參考下
    2017-09-09
  • springboot中操作redis實例分享

    springboot中操作redis實例分享

    本文介紹了如何在Spring?Boot應(yīng)用中整合Redis緩存技術(shù),包括配置Redis連接、定義Redis模板、實現(xiàn)Redis的基本操作以及使用Spring?Cache注解。這些內(nèi)容可幫助開發(fā)者快速掌握Spring?Boot與Redis的集成,并提高應(yīng)用性能。
    2023-06-06
  • 淺談Redis變慢的原因及排查方法

    淺談Redis變慢的原因及排查方法

    本文主要介紹了淺談Redis變慢的原因及排查方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2022-06-06
  • Redis數(shù)據(jù)庫安全詳解

    Redis數(shù)據(jù)庫安全詳解

    這篇文章主要為大家介紹了Redis數(shù)據(jù)庫安全詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-11-11
  • 一文帶你了解Redis怎么啟動以及使用

    一文帶你了解Redis怎么啟動以及使用

    對于Redis我們一般會使用到三種啟動方式:直接啟動、指定配置文件啟動、開機自啟動,下面這篇文章主要給大家介紹了關(guān)于Redis怎么啟動以及使用的相關(guān)資料,需要的朋友可以參考下
    2023-04-04

最新評論

新河县| 从化市| 洪洞县| 阿克苏市| 台江县| 北海市| 安顺市| 乐清市| 江安县| 肃南| 阳原县| 郯城县| 庆安县| 古交市| 成安县| 台湾省| 武陟县| 逊克县| 舒兰市| 香格里拉县| 弥勒县| 枞阳县| 贡山| 玉溪市| 焦作市| 囊谦县| 涡阳县| 台江县| 军事| 芜湖县| 吴川市| 花莲市| 巴林左旗| 玉树县| 论坛| 新兴县| 南木林县| 高邑县| 巴林左旗| 沾化县| 桃江县|