Merge branch '3.3.x' into 3.4.x

Closes gh-43832
This commit is contained in:
Andy Wilkinson 2025-01-15 12:15:19 +00:00
commit 1de3b5624f
2 changed files with 36 additions and 40 deletions

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -39,7 +39,7 @@ class PropertiesRedisConnectionDetails implements RedisConnectionDetails {
@Override @Override
public String getUsername() { public String getUsername() {
if (this.properties.getUrl() != null) { if (this.properties.getUrl() != null) {
ConnectionInfo connectionInfo = connectionInfo(this.properties.getUrl()); ConnectionInfo connectionInfo = ConnectionInfo.of(this.properties.getUrl());
return connectionInfo.getUsername(); return connectionInfo.getUsername();
} }
return this.properties.getUsername(); return this.properties.getUsername();
@ -48,7 +48,7 @@ class PropertiesRedisConnectionDetails implements RedisConnectionDetails {
@Override @Override
public String getPassword() { public String getPassword() {
if (this.properties.getUrl() != null) { if (this.properties.getUrl() != null) {
ConnectionInfo connectionInfo = connectionInfo(this.properties.getUrl()); ConnectionInfo connectionInfo = ConnectionInfo.of(this.properties.getUrl());
return connectionInfo.getPassword(); return connectionInfo.getPassword();
} }
return this.properties.getPassword(); return this.properties.getPassword();
@ -57,17 +57,13 @@ class PropertiesRedisConnectionDetails implements RedisConnectionDetails {
@Override @Override
public Standalone getStandalone() { public Standalone getStandalone() {
if (this.properties.getUrl() != null) { if (this.properties.getUrl() != null) {
ConnectionInfo connectionInfo = connectionInfo(this.properties.getUrl()); ConnectionInfo connectionInfo = ConnectionInfo.of(this.properties.getUrl());
return Standalone.of(connectionInfo.getUri().getHost(), connectionInfo.getUri().getPort(), return Standalone.of(connectionInfo.getUri().getHost(), connectionInfo.getUri().getPort(),
this.properties.getDatabase()); this.properties.getDatabase());
} }
return Standalone.of(this.properties.getHost(), this.properties.getPort(), this.properties.getDatabase()); return Standalone.of(this.properties.getHost(), this.properties.getPort(), this.properties.getDatabase());
} }
private ConnectionInfo connectionInfo(String url) {
return (url != null) ? RedisConnectionConfiguration.parseUrl(url) : null;
}
@Override @Override
public Sentinel getSentinel() { public Sentinel getSentinel() {
org.springframework.boot.autoconfigure.data.redis.RedisProperties.Sentinel sentinel = this.properties org.springframework.boot.autoconfigure.data.redis.RedisProperties.Sentinel sentinel = this.properties

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -172,14 +172,47 @@ abstract class RedisConnectionConfiguration {
} }
protected final boolean urlUsesSsl() { protected final boolean urlUsesSsl() {
return parseUrl(this.properties.getUrl()).isUseSsl(); return ConnectionInfo.of(this.properties.getUrl()).isUseSsl();
} }
protected final RedisConnectionDetails getConnectionDetails() { protected final RedisConnectionDetails getConnectionDetails() {
return this.connectionDetails; return this.connectionDetails;
} }
static ConnectionInfo parseUrl(String url) { static final class ConnectionInfo {
private final URI uri;
private final boolean useSsl;
private final String username;
private final String password;
private ConnectionInfo(URI uri, boolean useSsl, String username, String password) {
this.uri = uri;
this.useSsl = useSsl;
this.username = username;
this.password = password;
}
URI getUri() {
return this.uri;
}
boolean isUseSsl() {
return this.useSsl;
}
String getUsername() {
return this.username;
}
String getPassword() {
return this.password;
}
static ConnectionInfo of(String url) {
try { try {
URI uri = new URI(url); URI uri = new URI(url);
String scheme = uri.getScheme(); String scheme = uri.getScheme();
@ -207,39 +240,6 @@ abstract class RedisConnectionConfiguration {
} }
} }
static class ConnectionInfo {
private final URI uri;
private final boolean useSsl;
private final String username;
private final String password;
ConnectionInfo(URI uri, boolean useSsl, String username, String password) {
this.uri = uri;
this.useSsl = useSsl;
this.username = username;
this.password = password;
}
URI getUri() {
return this.uri;
}
boolean isUseSsl() {
return this.useSsl;
}
String getUsername() {
return this.username;
}
String getPassword() {
return this.password;
}
} }
} }