mirror of
https://github.com/continew-org/continew-starter.git
synced 2025-09-09 20:57:23 +08:00
chore(cache/redisson): 优化协议前缀变量命名
This commit is contained in:
@@ -51,10 +51,11 @@ import java.util.List;
|
|||||||
public class RedissonAutoConfiguration {
|
public class RedissonAutoConfiguration {
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(RedissonAutoConfiguration.class);
|
private static final Logger log = LoggerFactory.getLogger(RedissonAutoConfiguration.class);
|
||||||
|
|
||||||
private final RedissonProperties properties;
|
private final RedissonProperties properties;
|
||||||
private final RedisProperties redisProperties;
|
private final RedisProperties redisProperties;
|
||||||
private final ObjectMapper objectMapper;
|
private final ObjectMapper objectMapper;
|
||||||
|
private static final String REDIS_PROTOCOL_PREFIX = "redis://";
|
||||||
|
private static final String REDISS_PROTOCOL_PREFIX = "rediss://";
|
||||||
|
|
||||||
public RedissonAutoConfiguration(RedissonProperties properties,
|
public RedissonAutoConfiguration(RedissonProperties properties,
|
||||||
RedisProperties redisProperties,
|
RedisProperties redisProperties,
|
||||||
@@ -68,11 +69,13 @@ public class RedissonAutoConfiguration {
|
|||||||
public RedissonAutoConfigurationCustomizer redissonAutoConfigurationCustomizer() {
|
public RedissonAutoConfigurationCustomizer redissonAutoConfigurationCustomizer() {
|
||||||
return config -> {
|
return config -> {
|
||||||
RedissonProperties.Mode mode = properties.getMode();
|
RedissonProperties.Mode mode = properties.getMode();
|
||||||
String protocol = redisProperties.getSsl().isEnabled() ? "rediss://" : "redis://";
|
String protocolPrefix = redisProperties.getSsl().isEnabled()
|
||||||
|
? REDISS_PROTOCOL_PREFIX
|
||||||
|
: REDIS_PROTOCOL_PREFIX;
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case CLUSTER -> this.buildClusterModeConfig(config, protocol);
|
case CLUSTER -> this.buildClusterModeConfig(config, protocolPrefix);
|
||||||
case SENTINEL -> this.buildSentinelModeConfig(config, protocol);
|
case SENTINEL -> this.buildSentinelModeConfig(config, protocolPrefix);
|
||||||
default -> this.buildSingleModeConfig(config, protocol);
|
default -> this.buildSingleModeConfig(config, protocolPrefix);
|
||||||
}
|
}
|
||||||
// Jackson 处理
|
// Jackson 处理
|
||||||
config.setCodec(new JsonJacksonCodec(objectMapper));
|
config.setCodec(new JsonJacksonCodec(objectMapper));
|
||||||
@@ -83,10 +86,10 @@ public class RedissonAutoConfiguration {
|
|||||||
/**
|
/**
|
||||||
* 构建集群模式配置
|
* 构建集群模式配置
|
||||||
*
|
*
|
||||||
* @param config 配置
|
* @param config 配置
|
||||||
* @param protocol 协议
|
* @param protocolPrefix 协议前缀
|
||||||
*/
|
*/
|
||||||
private void buildClusterModeConfig(Config config, String protocol) {
|
private void buildClusterModeConfig(Config config, String protocolPrefix) {
|
||||||
ClusterServersConfig clusterServersConfig = config.useClusterServers();
|
ClusterServersConfig clusterServersConfig = config.useClusterServers();
|
||||||
ClusterServersConfig customClusterServersConfig = properties.getClusterServersConfig();
|
ClusterServersConfig customClusterServersConfig = properties.getClusterServersConfig();
|
||||||
if (null != customClusterServersConfig) {
|
if (null != customClusterServersConfig) {
|
||||||
@@ -96,7 +99,7 @@ public class RedissonAutoConfiguration {
|
|||||||
// 下方配置如果为空,则使用 Redis 的配置
|
// 下方配置如果为空,则使用 Redis 的配置
|
||||||
if (CollUtil.isEmpty(clusterServersConfig.getNodeAddresses())) {
|
if (CollUtil.isEmpty(clusterServersConfig.getNodeAddresses())) {
|
||||||
List<String> nodeList = redisProperties.getCluster().getNodes();
|
List<String> nodeList = redisProperties.getCluster().getNodes();
|
||||||
nodeList.stream().map(node -> protocol + node).forEach(clusterServersConfig::addNodeAddress);
|
nodeList.stream().map(node -> protocolPrefix + node).forEach(clusterServersConfig::addNodeAddress);
|
||||||
}
|
}
|
||||||
if (StrUtil.isBlank(clusterServersConfig.getPassword())) {
|
if (StrUtil.isBlank(clusterServersConfig.getPassword())) {
|
||||||
clusterServersConfig.setPassword(redisProperties.getPassword());
|
clusterServersConfig.setPassword(redisProperties.getPassword());
|
||||||
@@ -106,10 +109,10 @@ public class RedissonAutoConfiguration {
|
|||||||
/**
|
/**
|
||||||
* 构建哨兵模式配置
|
* 构建哨兵模式配置
|
||||||
*
|
*
|
||||||
* @param config 配置
|
* @param config 配置
|
||||||
* @param protocol 协议
|
* @param protocolPrefix 协议前缀
|
||||||
*/
|
*/
|
||||||
private void buildSentinelModeConfig(Config config, String protocol) {
|
private void buildSentinelModeConfig(Config config, String protocolPrefix) {
|
||||||
SentinelServersConfig sentinelServersConfig = config.useSentinelServers();
|
SentinelServersConfig sentinelServersConfig = config.useSentinelServers();
|
||||||
SentinelServersConfig customSentinelServersConfig = properties.getSentinelServersConfig();
|
SentinelServersConfig customSentinelServersConfig = properties.getSentinelServersConfig();
|
||||||
if (null != customSentinelServersConfig) {
|
if (null != customSentinelServersConfig) {
|
||||||
@@ -119,7 +122,7 @@ public class RedissonAutoConfiguration {
|
|||||||
// 下方配置如果为空,则使用 Redis 的配置
|
// 下方配置如果为空,则使用 Redis 的配置
|
||||||
if (CollUtil.isEmpty(sentinelServersConfig.getSentinelAddresses())) {
|
if (CollUtil.isEmpty(sentinelServersConfig.getSentinelAddresses())) {
|
||||||
List<String> nodeList = redisProperties.getSentinel().getNodes();
|
List<String> nodeList = redisProperties.getSentinel().getNodes();
|
||||||
nodeList.stream().map(node -> protocol + node).forEach(sentinelServersConfig::addSentinelAddress);
|
nodeList.stream().map(node -> protocolPrefix + node).forEach(sentinelServersConfig::addSentinelAddress);
|
||||||
}
|
}
|
||||||
if (StrUtil.isBlank(sentinelServersConfig.getPassword())) {
|
if (StrUtil.isBlank(sentinelServersConfig.getPassword())) {
|
||||||
sentinelServersConfig.setPassword(redisProperties.getPassword());
|
sentinelServersConfig.setPassword(redisProperties.getPassword());
|
||||||
@@ -132,10 +135,10 @@ public class RedissonAutoConfiguration {
|
|||||||
/**
|
/**
|
||||||
* 构建单机模式配置
|
* 构建单机模式配置
|
||||||
*
|
*
|
||||||
* @param config 配置
|
* @param config 配置
|
||||||
* @param protocol 协议
|
* @param protocolPrefix 协议前缀
|
||||||
*/
|
*/
|
||||||
private void buildSingleModeConfig(Config config, String protocol) {
|
private void buildSingleModeConfig(Config config, String protocolPrefix) {
|
||||||
SingleServerConfig singleServerConfig = config.useSingleServer();
|
SingleServerConfig singleServerConfig = config.useSingleServer();
|
||||||
SingleServerConfig customSingleServerConfig = properties.getSingleServerConfig();
|
SingleServerConfig customSingleServerConfig = properties.getSingleServerConfig();
|
||||||
if (null != customSingleServerConfig) {
|
if (null != customSingleServerConfig) {
|
||||||
@@ -147,8 +150,8 @@ public class RedissonAutoConfiguration {
|
|||||||
singleServerConfig.setPassword(redisProperties.getPassword());
|
singleServerConfig.setPassword(redisProperties.getPassword());
|
||||||
}
|
}
|
||||||
if (StrUtil.isBlank(singleServerConfig.getAddress())) {
|
if (StrUtil.isBlank(singleServerConfig.getAddress())) {
|
||||||
singleServerConfig.setAddress(protocol + redisProperties.getHost() + StringConstants.COLON + redisProperties
|
singleServerConfig.setAddress(protocolPrefix + redisProperties
|
||||||
.getPort());
|
.getHost() + StringConstants.COLON + redisProperties.getPort());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user