Both Jedis and Lettese clients support specifying a database in the URL * Jedis: https://github.com/redis/jedis/blob/master/src/main/java/redis/clients/jedis/util/JedisURIHelper.java * Lettuce: https://github.com/redis/lettuce/wiki/Redis-URI-and-connection-details
Unfortunately, spring-boot-autoconfigure ignore them
@Override
public Standalone getStandalone() {
if (this.properties.getUrl() != null) {
ConnectionInfo connectionInfo = connectionInfo(this.properties.getUrl());
return Standalone.of(connectionInfo.getUri().getHost(), connectionInfo.getUri().getPort(),
this.properties.getDatabase());
}
return Standalone.of(this.properties.getHost(), this.properties.getPort(), this.properties.getDatabase());
}
This causes the following URL actually connect to database 0
spring:
data:
redis:
url: redis://127.0.0.1:6379/8
The current workaround in my project is
spring: data: redis: url: redis://127.0.0.1:6379/8 database: 8-
(
Comment From: snicoll
@Demonese this is working as advertized. The documentation of the spring.data.redis.url property you used states:
Connection URL. Overrides host, port, username, and password. Example: redis:// user:password@example. com:6379
@mp911de do you think adding support for the database there would be useful?
Comment From: mp911de
It would be. When a URL is provided, arguments provided through the URL should take precedence over other properties.
Comment From: wilkinsona
Closing in favour of #43813.