in jetcache-starter/jetcache-autoconfigure/src/main/java/com/alicp/jetcache/autoconfigure/RedisAutoConfiguration.java [108:162]
private Object parsePool(ConfigTree ct) {
GenericObjectPoolConfig poolConfig = parsePoolConfig(ct);
Map<String, Object> cluster = ct.subTree("cluster"/*there is no dot*/).getProperties();
String host = ct.getProperty("host", (String) null);
int port = Integer.parseInt(ct.getProperty("port", "0"));
int timeout = Integer.parseInt(ct.getProperty("timeout", String.valueOf(Protocol.DEFAULT_TIMEOUT)));
int connectionTimeout = Integer.parseInt(ct.getProperty("connectionTimeout", String.valueOf(timeout)));
int soTimeout = Integer.parseInt(ct.getProperty("soTimeout", String.valueOf(timeout)));
String user = ct.getProperty("user", (String) null);
String password = ct.getProperty("password", (String) null);
int database = Integer.parseInt(ct.getProperty("database", String.valueOf(Protocol.DEFAULT_DATABASE)));
String clientName = ct.getProperty("clientName", (String) null);
boolean ssl = Boolean.parseBoolean(ct.getProperty("ssl", "false"));
String sentinels = ct.getProperty("sentinels", (String) null);//ip1:port,ip2:port
if (sentinels == null) {
if (cluster == null || cluster.size() == 0) {
Objects.requireNonNull(host, "host is required");
if (port == 0) {
throw new IllegalStateException("port is required");
}
return new JedisPool(poolConfig, host, port, connectionTimeout, soTimeout, user, password,
database, clientName, ssl);
} else {
int maxAttempt = Integer.parseInt(ct.getProperty("maxAttempt", "5"));
Set<HostAndPort> hostAndPortSet = cluster.values().stream()
.map(uri -> uri.toString().split(":"))
.map(hostAndPort -> new HostAndPort(hostAndPort[0], Integer.parseInt(hostAndPort[1])))
.collect(Collectors.toSet());
return new JedisCluster(hostAndPortSet, connectionTimeout, soTimeout, maxAttempt, user, password,
clientName, poolConfig, ssl);
}
} else {
String masterName = ct.getProperty("masterName", (String) null);
Objects.requireNonNull(masterName, "masterName is required");
int sentinelConnectionTimeout = Integer.parseInt(ct.getProperty("sentinelConnectionTimeout", String.valueOf(2000)));
int sentinelSoTimeout = Integer.parseInt(ct.getProperty("sentinelSoTimeout", String.valueOf(2000)));
String sentinelUser = ct.getProperty("sentinelUser", null);
String sentinelPassword = ct.getProperty("sentinelPassword", null);
String sentinelClientName = ct.getProperty("sentinelClientName", null);
String[] strings = sentinels.split(",");
HashSet<String> sentinelsSet = new HashSet<>();
for (String s : strings) {
if (s != null && !s.trim().equals("")) {
sentinelsSet.add(s.trim());
}
}
return new JedisSentinelPool(masterName, sentinelsSet, poolConfig, connectionTimeout, soTimeout,
user, password, database, clientName, sentinelConnectionTimeout, sentinelSoTimeout,
sentinelUser, sentinelPassword, sentinelClientName);
}
}