JedisURIHelper.getDBIndex() now returns 0 when db index is not provided
This commit is contained in:
@@ -68,7 +68,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
|
|||||||
}
|
}
|
||||||
|
|
||||||
Integer dbIndex = JedisURIHelper.getDBIndex(uri);
|
Integer dbIndex = JedisURIHelper.getDBIndex(uri);
|
||||||
if (dbIndex != null) {
|
if (dbIndex > 0) {
|
||||||
client.select(dbIndex);
|
client.select(dbIndex);
|
||||||
client.getStatusCodeReply();
|
client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,8 +14,13 @@ public class JedisURIHelper {
|
|||||||
public static Integer getDBIndex(URI uri) {
|
public static Integer getDBIndex(URI uri) {
|
||||||
String[] pathSplit = uri.getPath().split("/", 2);
|
String[] pathSplit = uri.getPath().split("/", 2);
|
||||||
if (pathSplit.length > 1) {
|
if (pathSplit.length > 1) {
|
||||||
return Integer.parseInt(pathSplit[1]);
|
String dbIndexStr = pathSplit[1];
|
||||||
|
if (dbIndexStr.isEmpty()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return Integer.parseInt(dbIndexStr);
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,6 +104,13 @@ public class JedisTest extends JedisCommandTestBase {
|
|||||||
@Test
|
@Test
|
||||||
public void allowUrlWithNoDBAndNoPassword() {
|
public void allowUrlWithNoDBAndNoPassword() {
|
||||||
Jedis jedis = new Jedis("redis://localhost:6380");
|
Jedis jedis = new Jedis("redis://localhost:6380");
|
||||||
|
jedis.auth("foobared");
|
||||||
|
assertEquals(jedis.getClient().getHost(), "localhost");
|
||||||
|
assertEquals(jedis.getClient().getPort(), 6380);
|
||||||
|
assertEquals(jedis.getDB(), (Long) 0L);
|
||||||
|
|
||||||
|
jedis = new Jedis("redis://localhost:6380/");
|
||||||
|
jedis.auth("foobared");
|
||||||
assertEquals(jedis.getClient().getHost(), "localhost");
|
assertEquals(jedis.getClient().getHost(), "localhost");
|
||||||
assertEquals(jedis.getClient().getPort(), 6380);
|
assertEquals(jedis.getClient().getPort(), 6380);
|
||||||
assertEquals(jedis.getDB(), (Long) 0L);
|
assertEquals(jedis.getDB(), (Long) 0L);
|
||||||
|
|||||||
Reference in New Issue
Block a user