Skip to content

Commit

Permalink
Revert "Merge pull request spring-projects#43813 from quaff"
Browse files Browse the repository at this point in the history
This reverts commit 4478bd5, reversing
changes made to c032e1f.

Signed-off-by: arefbehboudi <behboodiaref@gmail.com>
  • Loading branch information
wilkinsona authored and arefbehboudi committed Jan 29, 2025
1 parent 299a5e9 commit fd9294d
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
* @author Andy Wilkinson
* @author Phillip Webb
* @author Scott Frederick
* @author Yanming Zhou
*/
class PropertiesRedisConnectionDetails implements RedisConnectionDetails {

Expand Down Expand Up @@ -60,8 +59,7 @@ public Standalone getStandalone() {
if (this.properties.getUrl() != null) {
ConnectionInfo connectionInfo = ConnectionInfo.of(this.properties.getUrl());
return Standalone.of(connectionInfo.getUri().getHost(), connectionInfo.getUri().getPort(),
(connectionInfo.getDatabase() != null) ? connectionInfo.getDatabase()
: this.properties.getDatabase());
this.properties.getDatabase());
}
return Standalone.of(this.properties.getHost(), this.properties.getPort(), this.properties.getDatabase());
}
Expand All @@ -77,7 +75,7 @@ public Sentinel getSentinel() {

@Override
public int getDatabase() {
return getStandalone().getDatabase();
return PropertiesRedisConnectionDetails.this.properties.getDatabase();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.springframework.data.redis.connection.RedisSentinelConfiguration;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;

/**
* Base Redis connection configuration.
Expand All @@ -46,7 +45,6 @@
* @author Moritz Halbritter
* @author Andy Wilkinson
* @author Phillip Webb
* @author Yanming Zhou
*/
abstract class RedisConnectionConfiguration {

Expand Down Expand Up @@ -191,14 +189,11 @@ static final class ConnectionInfo {

private final String password;

private final Integer database;

private ConnectionInfo(URI uri, boolean useSsl, String username, String password, Integer database) {
private ConnectionInfo(URI uri, boolean useSsl, String username, String password) {
this.uri = uri;
this.useSsl = useSsl;
this.username = username;
this.password = password;
this.database = database;
}

URI getUri() {
Expand All @@ -217,10 +212,6 @@ String getPassword() {
return this.password;
}

Integer getDatabase() {
return this.database;
}

static ConnectionInfo of(String url) {
try {
URI uri = new URI(url);
Expand All @@ -242,14 +233,7 @@ static ConnectionInfo of(String url) {
password = candidate;
}
}
Integer database = null;
if (StringUtils.hasText(uri.getPath())) {
String[] pathSplit = uri.getPath().split("/", 2);
if (pathSplit.length > 1 && !pathSplit[1].isEmpty()) {
database = Integer.parseInt(pathSplit[1]);
}
}
return new ConnectionInfo(uri, useSsl, username, password, database);
return new ConnectionInfo(uri, useSsl, username, password);
}
catch (URISyntaxException ex) {
throw new RedisUrlSyntaxException(url, ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
* @author Mark Paluch
* @author Stephane Nicoll
* @author Scott Frederick
* @author Yanming Zhou
* @since 1.0.0
*/
@ConfigurationProperties(prefix = "spring.data.redis")
Expand All @@ -43,8 +42,8 @@ public class RedisProperties {
private int database = 0;

/**
* Connection URL. Overrides host, port, username, password, and database. Example:
* redis://user:password@example.com:6379/8
* Connection URL. Overrides host, port, username, and password. Example:
* redis://user:password@example.com:6379
*/
private String url;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,6 @@ void standaloneIsConfiguredFromUrl() {
RedisConnectionDetails.Standalone standalone = connectionDetails.getStandalone();
assertThat(standalone.getHost()).isEqualTo("example.com");
assertThat(standalone.getPort()).isEqualTo(1234);
assertThat(standalone.getDatabase()).isEqualTo(9999);
}

@Test
void standaloneIsConfiguredFromUrlWithoutDatabase() {
this.properties.setUrl("redis://example.com:1234");
this.properties.setDatabase(5);
PropertiesRedisConnectionDetails connectionDetails = new PropertiesRedisConnectionDetails(this.properties);
RedisConnectionDetails.Standalone standalone = connectionDetails.getStandalone();
assertThat(standalone.getHost()).isEqualTo("example.com");
assertThat(standalone.getPort()).isEqualTo(1234);
assertThat(standalone.getDatabase()).isEqualTo(5);
}

Expand Down Expand Up @@ -144,22 +133,9 @@ void sentinelIsConfigured() {
RedisProperties.Sentinel sentinel = new RedisProperties.Sentinel();
sentinel.setNodes(List.of("localhost:1111", "127.0.0.1:2222", "[::1]:3333"));
this.properties.setSentinel(sentinel);
this.properties.setDatabase(5);
PropertiesRedisConnectionDetails connectionDetails = new PropertiesRedisConnectionDetails(this.properties);
assertThat(connectionDetails.getSentinel().getNodes()).containsExactly(new Node("localhost", 1111),
new Node("127.0.0.1", 2222), new Node("[::1]", 3333));
assertThat(connectionDetails.getSentinel().getDatabase()).isEqualTo(5);
}

@Test
void sentinelDatabaseIsConfiguredFromUrl() {
RedisProperties.Sentinel sentinel = new RedisProperties.Sentinel();
sentinel.setNodes(List.of("localhost:1111", "127.0.0.1:2222", "[::1]:3333"));
this.properties.setSentinel(sentinel);
this.properties.setUrl("redis://example.com:1234/9999");
this.properties.setDatabase(5);
PropertiesRedisConnectionDetails connectionDetails = new PropertiesRedisConnectionDetails(this.properties);
assertThat(connectionDetails.getSentinel().getDatabase()).isEqualTo(9999);
}

}

0 comments on commit fd9294d

Please sign in to comment.