亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

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

如果查看redis中的值是這樣

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

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的實例化對象
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        //設(shè)置序列化Value的實例化對象
        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)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

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

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

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

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

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

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

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

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

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

    Java中的JWT使用詳解

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

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

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

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

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

    Redis在springboot中的使用教程

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

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

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

    SpringMVC配置多個properties文件之通配符解析

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

最新評論