欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

springboot使用redis緩存亂碼(key或者value亂碼)的解決

 更新時(shí)間:2023年11月23日 15:34:30   作者:追夢(mèng)者123  
在通過(guò)springboot緩存數(shù)據(jù)的時(shí)候,發(fā)現(xiàn)key是一堆很不友好的東西,本文主要介紹了springboot使用redis緩存亂碼(key或者value亂碼)的解決,感興趣的可以了解一下

如果查看redis中的值是這樣

創(chuàng)建一個(gè)配置類就可以解決

package com.deka.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.script.DefaultRedisScript;
import org.springframework.data.redis.core.script.RedisScript;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.scripting.support.ResourceScriptSource;


@Configuration
public class RedisConfig {

    @Autowired
    private RedisConnectionFactory redisConnectionFactory;

    @Autowired
    private RedisTemplate redisTemplate;

    @Bean
    public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory factory) {
        redisTemplate.setConnectionFactory(factory);
        Jackson2JsonRedisSerializer<Object> serializer = new Jackson2JsonRedisSerializer<Object>(Object.class);
        redisTemplate.setDefaultSerializer(serializer);
        //設(shè)置序列化Key的實(shí)例化對(duì)象
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        //設(shè)置序列化Value的實(shí)例化對(duì)象
        redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());

        return redisTemplate;
    }

    @Bean
    public RedisMessageListenerContainer redisContainer() {
        final RedisMessageListenerContainer container = new RedisMessageListenerContainer();
        container.setConnectionFactory(redisConnectionFactory);
        return container;
    }

    @Bean
    public RedisScript<Long> limitRedisScript() {
        DefaultRedisScript<Long> redisScript = new DefaultRedisScript<>();
        redisScript.setScriptSource(new ResourceScriptSource(new ClassPathResource("scripts/limit.lua")));
        redisScript.setResultType(Long.class);
        return redisScript;
    }
}

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

相關(guān)文章

  • 使用Java實(shí)現(xiàn)Excel導(dǎo)入并進(jìn)行數(shù)據(jù)校驗(yàn)

    使用Java實(shí)現(xiàn)Excel導(dǎo)入并進(jìn)行數(shù)據(jù)校驗(yàn)

    這篇文章主要為大家詳細(xì)介紹了Java如何根據(jù)下載的指定數(shù)據(jù)模板寫入數(shù)據(jù)和導(dǎo)入并進(jìn)行數(shù)據(jù)校驗(yàn),文中的示例代碼講解詳細(xì),需要的可以了解下
    2025-03-03
  • Java單線程程序?qū)崿F(xiàn)實(shí)現(xiàn)簡(jiǎn)單聊天功能

    Java單線程程序?qū)崿F(xiàn)實(shí)現(xiàn)簡(jiǎn)單聊天功能

    這篇文章主要介紹了Java單線程程序?qū)崿F(xiàn)實(shí)現(xiàn)簡(jiǎn)單聊天功能,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-10-10
  • JDBC數(shù)據(jù)庫(kù)連接步驟解析

    JDBC數(shù)據(jù)庫(kù)連接步驟解析

    這篇文章主要介紹了JDBC數(shù)據(jù)庫(kù)連接步驟解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-02-02
  • springBoot前后端分離項(xiàng)目中shiro的302跳轉(zhuǎn)問(wèn)題

    springBoot前后端分離項(xiàng)目中shiro的302跳轉(zhuǎn)問(wèn)題

    這篇文章主要介紹了springBoot前后端分離項(xiàng)目中shiro的302跳轉(zhuǎn)問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-12-12
  • Java中的JWT使用詳解

    Java中的JWT使用詳解

    這篇文章主要介紹了Java中的JWT使用詳解,JWT是一個(gè)開放標(biāo)準(zhǔn)(rfc7519),它定義了一種緊湊的、自包含的方式,用于在各方之間以JSON對(duì)象安全地傳輸信息,需要的朋友可以參考下
    2023-08-08
  • SpringBoot定時(shí)調(diào)度之Timer與Quartz詳解

    SpringBoot定時(shí)調(diào)度之Timer與Quartz詳解

    Java?中常用的定時(shí)調(diào)度框架有以下幾種:Timer、ScheduledExecutorService、Spring?Task和Quartz,本文主要來(lái)和大家講講他們的具體使用,需要的可以參考一下
    2023-06-06
  • springboot遠(yuǎn)程執(zhí)行服務(wù)器指令

    springboot遠(yuǎn)程執(zhí)行服務(wù)器指令

    這篇文章主要介紹了springboot遠(yuǎn)程執(zhí)行服務(wù)器指令,本例是java遠(yuǎn)程連接到服務(wù)器,去抓取查詢kubesphere中的etcd日志,并返回,需要的朋友可以參考下
    2023-09-09
  • Redis在springboot中的使用教程

    Redis在springboot中的使用教程

    這篇文章主要介紹了Redis在springboot中的使用教程,本文實(shí)例代碼相結(jié)合的形式給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2018-06-06
  • 構(gòu)建springboot自動(dòng)生成mapper文件和dao接口項(xiàng)目的步驟和配置方法

    構(gòu)建springboot自動(dòng)生成mapper文件和dao接口項(xiàng)目的步驟和配置方法

    這篇文章主要介紹了構(gòu)建springboot自動(dòng)生成mapper文件和dao接口項(xiàng)目的步驟和配置方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-05-05
  • SpringMVC配置多個(gè)properties文件之通配符解析

    SpringMVC配置多個(gè)properties文件之通配符解析

    這篇文章主要介紹了SpringMVC配置多個(gè)properties文件之通配符解析,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-09-09

最新評(píng)論