String.replaceFirsts compiles regex pattern on each call, it can be avoided just by getting index of `://`

Signed-off-by: Sergey Kuznetsov <iksss.88@gmail.com>
Signed-off-by: Sergey Kuznetsov <sergey.kuznetsov@infobip.com>
pull/5226/head
Sergey Kuznetsov 2 years ago
parent 8809f4b85d
commit ccccd4bd5e

@ -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