发现数据库乱码:
这数据库是来自rdids队列list实现的一个简单队列,停止使用该list的服务,查看里面的值,发现 乱码\xac\xed\x00\x05t\x00H,如下图:
很明发送数据端的问题,检查代码:
增加代码,值也序列化:
修改后的完整代码:
/**
* @author hua
* @date 2023-12-04 15:07
*/
public class SecondRedisConnection {
private static RedisConnectionFactory connectionFactory;
private static RedisTemplate<String, Object> redisTemplate;
static {
initialize();
}
private static void initialize() {
RedisStandaloneConfiguration redisStandaloneConfiguration=new RedisStandaloneConfiguration();
redisStandaloneConfiguration.setDatabase(2);
redisStandaloneConfiguration.setHostName("xx.xx.xx.xx");
redisStandaloneConfiguration.setPort(6379);
redisStandaloneConfiguration.setPassword("xxxxxxx");
LettuceConnectionFactory lettuceConnectionFactory = new LettuceConnectionFactory(redisStandaloneConfiguration);
lettuceConnectionFactory.afterPropertiesSet();
lettuceConnectionFactory.setTimeout(3000);
connectionFactory = lettuceConnectionFactory;
redisTemplate = new RedisTemplate();
redisTemplate.setConnectionFactory(connectionFactory);
//解决序列化乱码
redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setValueSerializer(new StringRedisSerializer());
redisTemplate.afterPropertiesSet();
}
public static RedisConnectionFactory getSecondRedisConnectionFactory() {
return connectionFactory;
}
public static RedisTemplate getSecondRedisTemplate() {
return redisTemplate;
}
}
发布后恢复正常,如下图: