提交 82050c40 编写于 作者: N Nikita Koksharov

Fixed - Spring Boot Starter doesn't convert properly list of sentinel addresses. #1731

上级 bc7ab0e5
......@@ -19,6 +19,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.redisson.Redisson;
......@@ -102,9 +103,9 @@ public class RedissonAutoConfiguration {
String[] nodes;
if (nodesValue instanceof String) {
nodes = ((String)nodesValue).split(",");
nodes = convert(Arrays.asList(((String)nodesValue).split(",")));
} else {
nodes = ((List<String>)nodesValue).toArray(new String[((List<String>)nodesValue).size()]);
nodes = convert((List<String>)nodesValue);
}
config = new Config();
......@@ -119,18 +120,11 @@ public class RedissonAutoConfiguration {
Method nodesMethod = ReflectionUtils.findMethod(clusterObject.getClass(), "getNodes");
List<String> nodesObject = (List) ReflectionUtils.invokeMethod(nodesMethod, clusterObject);
List<String> nodes = new ArrayList<String>();
for (String node : nodesObject) {
if (!node.startsWith("redis://") && !node.startsWith("rediss://")) {
nodes.add("redis://" + node);
} else {
nodes.add(node);
}
}
String[] nodes = convert(nodesObject);
config = new Config();
config.useClusterServers()
.addNodeAddress(nodes.toArray(new String[nodes.size()]))
.addNodeAddress(nodes)
.setConnectTimeout(timeout)
.setPassword(redisProperties.getPassword());
} else {
......@@ -151,7 +145,19 @@ public class RedissonAutoConfiguration {
return Redisson.create(config);
}
protected InputStream getConfigStream() throws IOException {
private String[] convert(List<String> nodesObject) {
List<String> nodes = new ArrayList<String>(nodesObject.size());
for (String node : nodesObject) {
if (!node.startsWith("redis://") && !node.startsWith("rediss://")) {
nodes.add("redis://" + node);
} else {
nodes.add(node);
}
}
return nodes.toArray(new String[nodes.size()]);
}
private InputStream getConfigStream() throws IOException {
Resource resource = ctx.getResource(redissonProperties.getConfig());
InputStream is = resource.getInputStream();
return is;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册