1. 修改 redis 配置信息
This commit is contained in:
parent
b2c58c73b8
commit
09c479e1b3
|
|
@ -19,6 +19,7 @@ import org.springframework.cache.annotation.CachingConfigurerSupport;
|
||||||
import org.springframework.cache.annotation.EnableCaching;
|
import org.springframework.cache.annotation.EnableCaching;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
@ -65,21 +66,31 @@ public class RedisConfiguration extends CachingConfigurerSupport {
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (ObjectUtil.isNotNull(clusterServerConfig)) {
|
if (ObjectUtil.isNotNull(clusterServerConfig)) {
|
||||||
List<String> nodes = clusterServerConfig.getNodes();
|
String nodes = clusterServerConfig.getNodes();
|
||||||
AssertUtil.invalidate(CollectionUtil.isEmpty(nodes), "redisson cluster 配置错误");
|
AssertUtil.invalidate(StringUtils.isEmpty(nodes), "redisson cluster 配置错误");
|
||||||
nodes = nodes.stream().map(s-> "redis://" + s).collect(Collectors.toList());
|
List<String> nodeList;
|
||||||
|
if (nodes.contains("redis://")){
|
||||||
|
nodeList = Arrays.stream(nodes.split(",")).toList();
|
||||||
|
}else {
|
||||||
|
nodeList = Arrays.stream(nodes.split(",")).map(s-> "redis://" + s).collect(Collectors.toList());
|
||||||
|
}
|
||||||
config.useClusterServers()
|
config.useClusterServers()
|
||||||
//设置redis key前缀
|
//设置redis key前缀
|
||||||
.setNameMapper(new KeyPrefixHandler(redissonProperties.getPrefix()))
|
.setNameMapper(new KeyPrefixHandler(redissonProperties.getPrefix()))
|
||||||
.setTimeout(redissonProperties.getTimeout())
|
.setTimeout(redissonProperties.getTimeout())
|
||||||
.setPassword(redissonProperties.getPassword())
|
.setPassword(redissonProperties.getPassword())
|
||||||
.setUsername(redissonProperties.getUsername())
|
.setUsername(redissonProperties.getUsername())
|
||||||
.setNodeAddresses(nodes);
|
.setNodeAddresses(nodeList);
|
||||||
;
|
;
|
||||||
} else if (ObjectUtil.isNotNull(sentinelServerConfig)){
|
} else if (ObjectUtil.isNotNull(sentinelServerConfig)){
|
||||||
List<String> nodes = clusterServerConfig.getNodes();
|
String nodes = clusterServerConfig.getNodes();
|
||||||
AssertUtil.invalidate(CollectionUtil.isEmpty(nodes), "redisson sentinel 配置错误");
|
AssertUtil.invalidate(StringUtils.isEmpty(nodes), "redisson sentinel 配置错误");
|
||||||
nodes = nodes.stream().map(s-> "redis://" + s).collect(Collectors.toList());
|
List<String> nodeList;
|
||||||
|
if (nodes.contains("redis://")){
|
||||||
|
nodeList = Arrays.stream(nodes.split(",")).toList();
|
||||||
|
}else {
|
||||||
|
nodeList = Arrays.stream(nodes.split(",")).map(s-> "redis://" + s).collect(Collectors.toList());
|
||||||
|
}
|
||||||
config.useSentinelServers()
|
config.useSentinelServers()
|
||||||
.setNameMapper(new KeyPrefixHandler(redissonProperties.getPrefix()))
|
.setNameMapper(new KeyPrefixHandler(redissonProperties.getPrefix()))
|
||||||
.setTimeout(redissonProperties.getTimeout())
|
.setTimeout(redissonProperties.getTimeout())
|
||||||
|
|
@ -87,7 +98,7 @@ public class RedisConfiguration extends CachingConfigurerSupport {
|
||||||
.setPassword(redissonProperties.getPassword())
|
.setPassword(redissonProperties.getPassword())
|
||||||
.setDatabase(sentinelServerConfig.getDatabase())
|
.setDatabase(sentinelServerConfig.getDatabase())
|
||||||
.setMasterName(sentinelServerConfig.getMasterName())
|
.setMasterName(sentinelServerConfig.getMasterName())
|
||||||
.setSentinelAddresses(nodes)
|
.setSentinelAddresses(nodeList)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
log.info("------------- 初始化 redis 配置 -------------");
|
log.info("------------- 初始化 redis 配置 -------------");
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ public class RedissonProperties {
|
||||||
/**
|
/**
|
||||||
* 集群
|
* 集群
|
||||||
*/
|
*/
|
||||||
private List<String> nodes;
|
private String nodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
|
@ -95,6 +95,6 @@ public class RedissonProperties {
|
||||||
/**
|
/**
|
||||||
* 地址
|
* 地址
|
||||||
*/
|
*/
|
||||||
private List<String> nodes;
|
private String nodes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue