首页 前端知识 org.springframework.data.redis.serializer.SerializationException: Could not read JSON: Illegal chara

org.springframework.data.redis.serializer.SerializationException: Could not read JSON: Illegal chara

2024-06-16 01:06:09 前端知识 前端哥 377 192 我要收藏
org.springframework.data.redis.serializer.SerializationException: Could not read JSON: Illegal character ((CTRL-CHAR, code 0)): only regular white space (\r, \n, \t) is allowed between tokens
at [Source: (byte[])" "[truncated 88118 bytes]; line: 1, column: 2]; nested exception is com.fasterxml.jackson.core.JsonParseException: Illegal character ((CTRL-CHAR, code 0)): only regular white space (\r, \n, \t) is allowed between tokens
at [Source: (byte[])" "[truncated 88118 bytes]; line: 1, column: 2]
复制

查看Redis的数据,发现无缘无故多了内容(\x00\x00)
在这里插入图片描述
经过一系列调试,问题出在这,没有设置时间单位
在这里插入图片描述
如果不设置时间单位,那么第三个会是偏移量
在这里插入图片描述

解决方案

加上时间单位
在这里插入图片描述

如果这个不能解决的话,可以改下RedisConfig配置是否正确

import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.*;
/**
* Redis配置类
*/
@Configuration
@EnableCaching
public class RedisConfig {
// 声明模板
/*
ref = 表示引用
value = 具体的值
<bean class="org.springframework.data.redis.core.RedisTemplate" >
<property name="defaultSerializer" ref = "">
</bean>
*/
@Bean
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(redisConnectionFactory);
GenericJackson2JsonRedisSerializer jackson2JsonRedisSerializer = new GenericJackson2JsonRedisSerializer();
// 设置值(value)的序列化采用FastJsonRedisSerializer。
redisTemplate.setValueSerializer(jackson2JsonRedisSerializer);
// 设置键(key)的序列化采用StringRedisSerializer。
redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setHashKeySerializer(new StringRedisSerializer());
redisTemplate.setHashValueSerializer(jackson2JsonRedisSerializer);
redisTemplate.afterPropertiesSet();
return redisTemplate;
}
}
复制
转载请注明出处或者链接地址:https://www.qianduange.cn//article/12289.html
标签
redis
评论
还可以输入200
共0条数据,当前/页
发布的文章

JQuery中的load()、$

2024-05-10 08:05:15

大家推荐的文章
会员中心 联系我 留言建议 回顶部
复制成功!