Merge pull request #5226 from ikss/url_resolver_fix

Reduce regex compilations in RedisURI
pull/5239/head
Nikita Koksharov 2 years ago committed by GitHub
commit 567e13e07a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -42,8 +42,7 @@ public class RedisURI {
} }
public RedisURI(String uri) { public RedisURI(String uri) {
if (!uri.startsWith("redis://") if (!uri.startsWith("redis://") && !uri.startsWith("rediss://")) {
&& !uri.startsWith("rediss://")) {
throw new IllegalArgumentException("Redis url should start with redis:// or rediss:// (for SSL connection)"); throw new IllegalArgumentException("Redis url should start with redis:// or rediss:// (for SSL connection)");
} }
@ -73,8 +72,9 @@ public class RedisURI {
} }
private String parseUrl(String uri) { private String parseUrl(String uri) {
String urlHost = uri.replaceFirst("redis://", "http://").replaceFirst("rediss://", "http://"); int hostStartIndex = uri.indexOf("://") + 3;
String ipV6Host = uri.substring(uri.indexOf("://")+3, uri.lastIndexOf(":")); String urlHost = "http://" + uri.substring(hostStartIndex);
String ipV6Host = uri.substring(hostStartIndex, uri.lastIndexOf(":"));
if (ipV6Host.contains("@")) { if (ipV6Host.contains("@")) {
ipV6Host = ipV6Host.split("@")[1]; ipV6Host = ipV6Host.split("@")[1];
} }

Loading…
Cancel
Save