由于使用redisson来存储list,返回的数据格式总是不对
原因是配置的序列化格式不对
java
@Bean(value = "redissonDtClient")
public RedissonClient redissonClient() {
RedisConnectionProperties.RedisConfigEntity configEntity = properties.getDt();
log.info("========= init redisson client ========= {}", configEntity.toString());
Config config = new Config();
String redisAddr = "redis://" + configEntity.getHostname() + ":" + configEntity.getPort();
SingleServerConfig singleServerConfig = config.useSingleServer();
String password = "";
if (StringUtils.isNotEmpty(configEntity.getPassword())) {
if (StringUtils.isNotEmpty(configEntity.getUsername())) {
password = configEntity.getUsername() + ":" + configEntity.getPassword();
} else {
password = configEntity.getPassword();
}
}
if (StringUtils.isNotEmpty(password)) {
singleServerConfig.setPassword(password);
}
singleServerConfig.setDatabase(configEntity.getDatabase());
singleServerConfig.setAddress(redisAddr);
config.setCodec(new StringCodec());//这里配置成了string格式的
config.setExecutor(new ThreadPoolExecutor(CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, 1, TimeUnit.MINUTES,
new LinkedBlockingQueue<>(), r -> new Thread(r, "redisson-executor-"
+ redissonExecutorThread.incrementAndGet())));
singleServerConfig.setClientName(appName + "|redisson|" + ip);
return Redisson.create(config);
}
应该配置成json格式的
java
config.setCodec(new JsonJacksonCodec());//更新为json序列化
这样就可以了