|
|
|
@ -22,8 +22,6 @@ import java.net.UnknownHostException;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
|
import org.apache.commons.pool2.impl.GenericObjectPool;
|
|
|
|
|
import redis.clients.jedis.Jedis;
|
|
|
|
|
import redis.clients.jedis.JedisPoolConfig;
|
|
|
|
@ -66,8 +64,6 @@ import org.springframework.util.StringUtils;
|
|
|
|
|
@EnableConfigurationProperties(RedisProperties.class)
|
|
|
|
|
public class RedisAutoConfiguration {
|
|
|
|
|
|
|
|
|
|
private static final Log logger = LogFactory.getLog(RedisAutoConfiguration.class);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Redis connection configuration.
|
|
|
|
|
*/
|
|
|
|
@ -98,21 +94,20 @@ public class RedisAutoConfiguration {
|
|
|
|
|
|
|
|
|
|
protected final JedisConnectionFactory applyProperties(
|
|
|
|
|
JedisConnectionFactory factory) {
|
|
|
|
|
if (StringUtils.hasText(this.properties.getUrl())) {
|
|
|
|
|
if (this.properties.getUrl().startsWith("rediss://")) {
|
|
|
|
|
configureConnection(factory);
|
|
|
|
|
if (this.properties.isSsl()) {
|
|
|
|
|
factory.setUseSsl(true);
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
URI redisURI = new URI(this.properties.getUrl());
|
|
|
|
|
factory.setHostName(redisURI.getHost());
|
|
|
|
|
factory.setPort(redisURI.getPort());
|
|
|
|
|
if (redisURI.getUserInfo() != null) {
|
|
|
|
|
factory.setPassword(redisURI.getUserInfo().split(":", 2)[1]);
|
|
|
|
|
}
|
|
|
|
|
factory.setDatabase(this.properties.getDatabase());
|
|
|
|
|
if (this.properties.getTimeout() > 0) {
|
|
|
|
|
factory.setTimeout(this.properties.getTimeout());
|
|
|
|
|
}
|
|
|
|
|
catch (URISyntaxException e) {
|
|
|
|
|
logger.error("Incorrect spring.redis.url", e);
|
|
|
|
|
return factory;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void configureConnection(JedisConnectionFactory factory) {
|
|
|
|
|
if (StringUtils.hasText(this.properties.getUrl())) {
|
|
|
|
|
configureConnectionFromUrl(factory);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
factory.setHostName(this.properties.getHost());
|
|
|
|
@ -121,14 +116,30 @@ public class RedisAutoConfiguration {
|
|
|
|
|
factory.setPassword(this.properties.getPassword());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (this.properties.isSsl()) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void configureConnectionFromUrl(JedisConnectionFactory factory) {
|
|
|
|
|
String url = this.properties.getUrl();
|
|
|
|
|
if (url.startsWith("rediss://")) {
|
|
|
|
|
factory.setUseSsl(true);
|
|
|
|
|
}
|
|
|
|
|
factory.setDatabase(this.properties.getDatabase());
|
|
|
|
|
if (this.properties.getTimeout() > 0) {
|
|
|
|
|
factory.setTimeout(this.properties.getTimeout());
|
|
|
|
|
try {
|
|
|
|
|
URI uri = new URI(url);
|
|
|
|
|
factory.setHostName(uri.getHost());
|
|
|
|
|
factory.setPort(uri.getPort());
|
|
|
|
|
if (uri.getUserInfo() != null) {
|
|
|
|
|
String password = uri.getUserInfo();
|
|
|
|
|
int index = password.lastIndexOf(":");
|
|
|
|
|
if (index >= 0) {
|
|
|
|
|
password = password.substring(index + 1);
|
|
|
|
|
}
|
|
|
|
|
factory.setPassword(password);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (URISyntaxException ex) {
|
|
|
|
|
throw new IllegalArgumentException("Malformed 'spring.redis.url' " + url,
|
|
|
|
|
ex);
|
|
|
|
|
}
|
|
|
|
|
return factory;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected final RedisSentinelConfiguration getSentinelConfig() {
|
|
|
|
|