|
|
|
@ -48,6 +48,7 @@ import org.springframework.util.ReflectionUtils;
|
|
|
|
|
*
|
|
|
|
|
* @author Nikita Koksharov
|
|
|
|
|
* @author Nikos Kakavas (https://github.com/nikakis)
|
|
|
|
|
* @author AnJia (https://anjia0532.github.io/)
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
@Configuration
|
|
|
|
@ -56,6 +57,9 @@ import org.springframework.util.ReflectionUtils;
|
|
|
|
|
@EnableConfigurationProperties({RedissonProperties.class, RedisProperties.class})
|
|
|
|
|
public class RedissonAutoConfiguration {
|
|
|
|
|
|
|
|
|
|
private static final String REDIS_PROTOCOL_PREFIX = "redis://";
|
|
|
|
|
private static final String REDISS_PROTOCOL_PREFIX = "rediss://";
|
|
|
|
|
|
|
|
|
|
@Autowired(required = false)
|
|
|
|
|
private List<RedissonAutoConfigurationCustomizer> redissonAutoConfigurationCustomizers;
|
|
|
|
|
|
|
|
|
@ -108,14 +112,24 @@ public class RedissonAutoConfiguration {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (redissonProperties.getConfig() != null) {
|
|
|
|
|
try {
|
|
|
|
|
config = Config.fromYAML(redissonProperties.getConfig());
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
try {
|
|
|
|
|
config = Config.fromJSON(redissonProperties.getConfig());
|
|
|
|
|
} catch (IOException e1) {
|
|
|
|
|
throw new IllegalArgumentException("Can't parse config", e1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else if (redissonProperties.getFile() != null) {
|
|
|
|
|
try {
|
|
|
|
|
InputStream is = getConfigStream();
|
|
|
|
|
config = Config.fromJSON(is);
|
|
|
|
|
config = Config.fromYAML(is);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
// trying next format
|
|
|
|
|
try {
|
|
|
|
|
InputStream is = getConfigStream();
|
|
|
|
|
config = Config.fromYAML(is);
|
|
|
|
|
config = Config.fromJSON(is);
|
|
|
|
|
} catch (IOException e1) {
|
|
|
|
|
throw new IllegalArgumentException("Can't parse config", e1);
|
|
|
|
|
}
|
|
|
|
@ -152,10 +166,10 @@ public class RedissonAutoConfiguration {
|
|
|
|
|
.setPassword(redisProperties.getPassword());
|
|
|
|
|
} else {
|
|
|
|
|
config = new Config();
|
|
|
|
|
String prefix = "redis://";
|
|
|
|
|
String prefix = REDIS_PROTOCOL_PREFIX;
|
|
|
|
|
Method method = ReflectionUtils.findMethod(RedisProperties.class, "isSsl");
|
|
|
|
|
if (method != null && (Boolean)ReflectionUtils.invokeMethod(method, redisProperties)) {
|
|
|
|
|
prefix = "rediss://";
|
|
|
|
|
prefix = REDISS_PROTOCOL_PREFIX;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
config.useSingleServer()
|
|
|
|
@ -175,8 +189,8 @@ public class RedissonAutoConfiguration {
|
|
|
|
|
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);
|
|
|
|
|
if (!node.startsWith(REDIS_PROTOCOL_PREFIX) && !node.startsWith(REDISS_PROTOCOL_PREFIX)) {
|
|
|
|
|
nodes.add(REDIS_PROTOCOL_PREFIX + node);
|
|
|
|
|
} else {
|
|
|
|
|
nodes.add(node);
|
|
|
|
|
}
|
|
|
|
|