Skip to content

Commit 7d34e6d

Browse files
committed
Revert "Merge pull request #43813 from quaff"
This reverts commit 4478bd5, reversing changes made to c032e1f.
1 parent 4478bd5 commit 7d34e6d

File tree

4 files changed

+6
-49
lines changed

4 files changed

+6
-49
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/redis/PropertiesRedisConnectionDetails.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
* @author Andy Wilkinson
2828
* @author Phillip Webb
2929
* @author Scott Frederick
30-
* @author Yanming Zhou
3130
*/
3231
class PropertiesRedisConnectionDetails implements RedisConnectionDetails {
3332

@@ -60,8 +59,7 @@ public Standalone getStandalone() {
6059
if (this.properties.getUrl() != null) {
6160
ConnectionInfo connectionInfo = ConnectionInfo.of(this.properties.getUrl());
6261
return Standalone.of(connectionInfo.getUri().getHost(), connectionInfo.getUri().getPort(),
63-
(connectionInfo.getDatabase() != null) ? connectionInfo.getDatabase()
64-
: this.properties.getDatabase());
62+
this.properties.getDatabase());
6563
}
6664
return Standalone.of(this.properties.getHost(), this.properties.getPort(), this.properties.getDatabase());
6765
}
@@ -77,7 +75,7 @@ public Sentinel getSentinel() {
7775

7876
@Override
7977
public int getDatabase() {
80-
return getStandalone().getDatabase();
78+
return PropertiesRedisConnectionDetails.this.properties.getDatabase();
8179
}
8280

8381
@Override

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/redis/RedisConnectionConfiguration.java

+2-18
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import org.springframework.data.redis.connection.RedisSentinelConfiguration;
3434
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
3535
import org.springframework.util.ClassUtils;
36-
import org.springframework.util.StringUtils;
3736

3837
/**
3938
* Base Redis connection configuration.
@@ -46,7 +45,6 @@
4645
* @author Moritz Halbritter
4746
* @author Andy Wilkinson
4847
* @author Phillip Webb
49-
* @author Yanming Zhou
5048
*/
5149
abstract class RedisConnectionConfiguration {
5250

@@ -191,14 +189,11 @@ static final class ConnectionInfo {
191189

192190
private final String password;
193191

194-
private final Integer database;
195-
196-
private ConnectionInfo(URI uri, boolean useSsl, String username, String password, Integer database) {
192+
private ConnectionInfo(URI uri, boolean useSsl, String username, String password) {
197193
this.uri = uri;
198194
this.useSsl = useSsl;
199195
this.username = username;
200196
this.password = password;
201-
this.database = database;
202197
}
203198

204199
URI getUri() {
@@ -217,10 +212,6 @@ String getPassword() {
217212
return this.password;
218213
}
219214

220-
Integer getDatabase() {
221-
return this.database;
222-
}
223-
224215
static ConnectionInfo of(String url) {
225216
try {
226217
URI uri = new URI(url);
@@ -242,14 +233,7 @@ static ConnectionInfo of(String url) {
242233
password = candidate;
243234
}
244235
}
245-
Integer database = null;
246-
if (StringUtils.hasText(uri.getPath())) {
247-
String[] pathSplit = uri.getPath().split("/", 2);
248-
if (pathSplit.length > 1 && !pathSplit[1].isEmpty()) {
249-
database = Integer.parseInt(pathSplit[1]);
250-
}
251-
}
252-
return new ConnectionInfo(uri, useSsl, username, password, database);
236+
return new ConnectionInfo(uri, useSsl, username, password);
253237
}
254238
catch (URISyntaxException ex) {
255239
throw new RedisUrlSyntaxException(url, ex);

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/redis/RedisProperties.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
* @author Mark Paluch
3232
* @author Stephane Nicoll
3333
* @author Scott Frederick
34-
* @author Yanming Zhou
3534
* @since 1.0.0
3635
*/
3736
@ConfigurationProperties(prefix = "spring.data.redis")
@@ -43,8 +42,8 @@ public class RedisProperties {
4342
private int database = 0;
4443

4544
/**
46-
* Connection URL. Overrides host, port, username, password, and database. Example:
47-
* redis://user:[email protected]:6379/8
45+
* Connection URL. Overrides host, port, username, and password. Example:
46+
* redis://user:[email protected]:6379
4847
*/
4948
private String url;
5049

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/PropertiesRedisConnectionDetailsTests.java

-24
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,6 @@ void standaloneIsConfiguredFromUrl() {
103103
RedisConnectionDetails.Standalone standalone = connectionDetails.getStandalone();
104104
assertThat(standalone.getHost()).isEqualTo("example.com");
105105
assertThat(standalone.getPort()).isEqualTo(1234);
106-
assertThat(standalone.getDatabase()).isEqualTo(9999);
107-
}
108-
109-
@Test
110-
void standaloneIsConfiguredFromUrlWithoutDatabase() {
111-
this.properties.setUrl("redis://example.com:1234");
112-
this.properties.setDatabase(5);
113-
PropertiesRedisConnectionDetails connectionDetails = new PropertiesRedisConnectionDetails(this.properties);
114-
RedisConnectionDetails.Standalone standalone = connectionDetails.getStandalone();
115-
assertThat(standalone.getHost()).isEqualTo("example.com");
116-
assertThat(standalone.getPort()).isEqualTo(1234);
117106
assertThat(standalone.getDatabase()).isEqualTo(5);
118107
}
119108

@@ -144,22 +133,9 @@ void sentinelIsConfigured() {
144133
RedisProperties.Sentinel sentinel = new RedisProperties.Sentinel();
145134
sentinel.setNodes(List.of("localhost:1111", "127.0.0.1:2222", "[::1]:3333"));
146135
this.properties.setSentinel(sentinel);
147-
this.properties.setDatabase(5);
148136
PropertiesRedisConnectionDetails connectionDetails = new PropertiesRedisConnectionDetails(this.properties);
149137
assertThat(connectionDetails.getSentinel().getNodes()).containsExactly(new Node("localhost", 1111),
150138
new Node("127.0.0.1", 2222), new Node("[::1]", 3333));
151-
assertThat(connectionDetails.getSentinel().getDatabase()).isEqualTo(5);
152-
}
153-
154-
@Test
155-
void sentinelDatabaseIsConfiguredFromUrl() {
156-
RedisProperties.Sentinel sentinel = new RedisProperties.Sentinel();
157-
sentinel.setNodes(List.of("localhost:1111", "127.0.0.1:2222", "[::1]:3333"));
158-
this.properties.setSentinel(sentinel);
159-
this.properties.setUrl("redis://example.com:1234/9999");
160-
this.properties.setDatabase(5);
161-
PropertiesRedisConnectionDetails connectionDetails = new PropertiesRedisConnectionDetails(this.properties);
162-
assertThat(connectionDetails.getSentinel().getDatabase()).isEqualTo(9999);
163139
}
164140

165141
}

0 commit comments

Comments
 (0)