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的實(shí)例化對象
redisTemplate.setKeySerializer(new StringRedisSerializer());
//設(shè)置序列化Value的實(shí)例化對象
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)文章希望大家以后多多支持腳本之家!
- SpringBoot項目中使用redis緩存的方法步驟
- SpringBoot 開啟Redis緩存及使用方法
- springboot+mybatis+redis 二級緩存問題實(shí)例詳解
- 淺談SpringBoot集成Redis實(shí)現(xiàn)緩存處理(Spring AOP實(shí)現(xiàn))
- SpringBoot2整合Redis緩存三步驟代碼詳解
- SpringBoot+SpringCache實(shí)現(xiàn)兩級緩存(Redis+Caffeine)
- 詳解SpringBoot集成Redis來實(shí)現(xiàn)緩存技術(shù)方案
- SpringBoot2.3整合redis緩存自定義序列化的實(shí)現(xiàn)
- SpringBoot使用Redis緩存MySql的方法步驟
- SpringBoot使用Redis緩存的實(shí)現(xiàn)方法
- SpringBoot redis分布式緩存實(shí)現(xiàn)過程解析
相關(guān)文章
使用Java實(shí)現(xiàn)Excel導(dǎo)入并進(jìn)行數(shù)據(jù)校驗
這篇文章主要為大家詳細(xì)介紹了Java如何根據(jù)下載的指定數(shù)據(jù)模板寫入數(shù)據(jù)和導(dǎo)入并進(jìn)行數(shù)據(jù)校驗,文中的示例代碼講解詳細(xì),需要的可以了解下2025-03-03
Java單線程程序?qū)崿F(xiàn)實(shí)現(xiàn)簡單聊天功能
這篇文章主要介紹了Java單線程程序?qū)崿F(xiàn)實(shí)現(xiàn)簡單聊天功能,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2020-10-10
springBoot前后端分離項目中shiro的302跳轉(zhuǎn)問題
這篇文章主要介紹了springBoot前后端分離項目中shiro的302跳轉(zhuǎn)問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-12-12
SpringBoot定時調(diào)度之Timer與Quartz詳解
Java?中常用的定時調(diào)度框架有以下幾種:Timer、ScheduledExecutorService、Spring?Task和Quartz,本文主要來和大家講講他們的具體使用,需要的可以參考一下2023-06-06
springboot遠(yuǎn)程執(zhí)行服務(wù)器指令
這篇文章主要介紹了springboot遠(yuǎn)程執(zhí)行服務(wù)器指令,本例是java遠(yuǎn)程連接到服務(wù)器,去抓取查詢kubesphere中的etcd日志,并返回,需要的朋友可以參考下2023-09-09
構(gòu)建springboot自動生成mapper文件和dao接口項目的步驟和配置方法
這篇文章主要介紹了構(gòu)建springboot自動生成mapper文件和dao接口項目的步驟和配置方法,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-05-05
SpringMVC配置多個properties文件之通配符解析
這篇文章主要介紹了SpringMVC配置多個properties文件之通配符解析,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-09-09

