Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: The connection information in RedisProperties configuration has higher priority. #4848

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
*
Expand All @@ -66,6 +67,8 @@ public class RedissonAutoConfiguration {

private static final String REDIS_PROTOCOL_PREFIX = "redis://";
private static final String REDISS_PROTOCOL_PREFIX = "rediss://";
private static final String DEFAULT_HOST = "localhost";
private static final int DEFAULT_PORT = 6379;

@Autowired(required = false)
private List<RedissonAutoConfigurationCustomizer> redissonAutoConfigurationCustomizers;
Expand Down Expand Up @@ -178,7 +181,10 @@ public RedissonClient redisson() throws IOException {
throw new IllegalArgumentException("Can't parse config", e1);
}
}
} else if (redisProperties.getSentinel() != null) {
} else {
config = new Config();
}
if (redisProperties.getSentinel() != null) {
Method nodesMethod = ReflectionUtils.findMethod(Sentinel.class, "getNodes");
Object nodesValue = ReflectionUtils.invokeMethod(nodesMethod, redisProperties.getSentinel());

Expand All @@ -188,8 +194,6 @@ public RedissonClient redisson() throws IOException {
} else {
nodes = convert((List<String>)nodesValue);
}

config = new Config();
SentinelServersConfig c = config.useSentinelServers()
.setMasterName(redisProperties.getSentinel().getMaster())
.addSentinelAddress(nodes)
Expand All @@ -210,7 +214,6 @@ public RedissonClient redisson() throws IOException {

String[] nodes = convert(nodesObject);

config = new Config();
ClusterServersConfig c = config.useClusterServers()
.addNodeAddress(nodes)
.setUsername(username)
Expand All @@ -222,8 +225,8 @@ public RedissonClient redisson() throws IOException {
if (connectTimeoutMethod != null && timeout != null) {
c.setTimeout(timeout);
}
} else {
config = new Config();
} else if (!Objects.equals(DEFAULT_HOST, redisProperties.getHost()) || redisProperties.getPort() != DEFAULT_PORT
|| redisProperties.getDatabase() != 0 || redisProperties.getPassword() != null) {
String prefix = REDIS_PROTOCOL_PREFIX;
Method method = ReflectionUtils.findMethod(RedisProperties.class, "isSsl");
if (method != null && (Boolean)ReflectionUtils.invokeMethod(method, redisProperties)) {
Expand Down