|
|
|
|
@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
|
|
|
|
|
/* |
|
|
|
|
* Copyright 2012-2024 the original author or authors. |
|
|
|
|
* Copyright 2012-2025 the original author or authors. |
|
|
|
|
* |
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
|
@ -172,42 +172,14 @@ abstract class RedisConnectionConfiguration {
@@ -172,42 +172,14 @@ abstract class RedisConnectionConfiguration {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected final boolean urlUsesSsl() { |
|
|
|
|
return parseUrl(this.properties.getUrl()).isUseSsl(); |
|
|
|
|
return ConnectionInfo.of(this.properties.getUrl()).isUseSsl(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected final RedisConnectionDetails getConnectionDetails() { |
|
|
|
|
return this.connectionDetails; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static ConnectionInfo parseUrl(String url) { |
|
|
|
|
try { |
|
|
|
|
URI uri = new URI(url); |
|
|
|
|
String scheme = uri.getScheme(); |
|
|
|
|
if (!"redis".equals(scheme) && !"rediss".equals(scheme)) { |
|
|
|
|
throw new RedisUrlSyntaxException(url); |
|
|
|
|
} |
|
|
|
|
boolean useSsl = ("rediss".equals(scheme)); |
|
|
|
|
String username = null; |
|
|
|
|
String password = null; |
|
|
|
|
if (uri.getUserInfo() != null) { |
|
|
|
|
String candidate = uri.getUserInfo(); |
|
|
|
|
int index = candidate.indexOf(':'); |
|
|
|
|
if (index >= 0) { |
|
|
|
|
username = candidate.substring(0, index); |
|
|
|
|
password = candidate.substring(index + 1); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
password = candidate; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return new ConnectionInfo(uri, useSsl, username, password); |
|
|
|
|
} |
|
|
|
|
catch (URISyntaxException ex) { |
|
|
|
|
throw new RedisUrlSyntaxException(url, ex); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static class ConnectionInfo { |
|
|
|
|
static final class ConnectionInfo { |
|
|
|
|
|
|
|
|
|
private final URI uri; |
|
|
|
|
|
|
|
|
|
@ -217,7 +189,7 @@ abstract class RedisConnectionConfiguration {
@@ -217,7 +189,7 @@ abstract class RedisConnectionConfiguration {
|
|
|
|
|
|
|
|
|
|
private final String password; |
|
|
|
|
|
|
|
|
|
ConnectionInfo(URI uri, boolean useSsl, String username, String password) { |
|
|
|
|
private ConnectionInfo(URI uri, boolean useSsl, String username, String password) { |
|
|
|
|
this.uri = uri; |
|
|
|
|
this.useSsl = useSsl; |
|
|
|
|
this.username = username; |
|
|
|
|
@ -240,6 +212,34 @@ abstract class RedisConnectionConfiguration {
@@ -240,6 +212,34 @@ abstract class RedisConnectionConfiguration {
|
|
|
|
|
return this.password; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static ConnectionInfo of(String url) { |
|
|
|
|
try { |
|
|
|
|
URI uri = new URI(url); |
|
|
|
|
String scheme = uri.getScheme(); |
|
|
|
|
if (!"redis".equals(scheme) && !"rediss".equals(scheme)) { |
|
|
|
|
throw new RedisUrlSyntaxException(url); |
|
|
|
|
} |
|
|
|
|
boolean useSsl = ("rediss".equals(scheme)); |
|
|
|
|
String username = null; |
|
|
|
|
String password = null; |
|
|
|
|
if (uri.getUserInfo() != null) { |
|
|
|
|
String candidate = uri.getUserInfo(); |
|
|
|
|
int index = candidate.indexOf(':'); |
|
|
|
|
if (index >= 0) { |
|
|
|
|
username = candidate.substring(0, index); |
|
|
|
|
password = candidate.substring(index + 1); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
password = candidate; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return new ConnectionInfo(uri, useSsl, username, password); |
|
|
|
|
} |
|
|
|
|
catch (URISyntaxException ex) { |
|
|
|
|
throw new RedisUrlSyntaxException(url, ex); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|