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

pull/1792/head
Nikita Koksharov 6 years ago
parent bc7ab0e586
commit 82050c404a

@ -19,6 +19,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import org.redisson.Redisson; import org.redisson.Redisson;
@ -102,9 +103,9 @@ public class RedissonAutoConfiguration {
String[] nodes; String[] nodes;
if (nodesValue instanceof String) { if (nodesValue instanceof String) {
nodes = ((String)nodesValue).split(","); nodes = convert(Arrays.asList(((String)nodesValue).split(",")));
} else { } else {
nodes = ((List<String>)nodesValue).toArray(new String[((List<String>)nodesValue).size()]); nodes = convert((List<String>)nodesValue);
} }
config = new Config(); config = new Config();
@ -119,18 +120,11 @@ public class RedissonAutoConfiguration {
Method nodesMethod = ReflectionUtils.findMethod(clusterObject.getClass(), "getNodes"); Method nodesMethod = ReflectionUtils.findMethod(clusterObject.getClass(), "getNodes");
List<String> nodesObject = (List) ReflectionUtils.invokeMethod(nodesMethod, clusterObject); List<String> nodesObject = (List) ReflectionUtils.invokeMethod(nodesMethod, clusterObject);
List<String> nodes = new ArrayList<String>(); String[] nodes = convert(nodesObject);
for (String node : nodesObject) {
if (!node.startsWith("redis://") && !node.startsWith("rediss://")) {
nodes.add("redis://" + node);
} else {
nodes.add(node);
}
}
config = new Config(); config = new Config();
config.useClusterServers() config.useClusterServers()
.addNodeAddress(nodes.toArray(new String[nodes.size()])) .addNodeAddress(nodes)
.setConnectTimeout(timeout) .setConnectTimeout(timeout)
.setPassword(redisProperties.getPassword()); .setPassword(redisProperties.getPassword());
} else { } else {
@ -151,7 +145,19 @@ public class RedissonAutoConfiguration {
return Redisson.create(config); 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()); Resource resource = ctx.getResource(redissonProperties.getConfig());
InputStream is = resource.getInputStream(); InputStream is = resource.getInputStream();
return is; return is;

Loading…
Cancel
Save