Make it better to use URI from Jedis / JedisPool

* no need to provide password / DB index when user uses URI
* can provide timeout when user users URI
This commit is contained in:
Jungtaek Lim
2014-06-15 21:50:38 +09:00
parent e05eaa2b07
commit 1d29b759fe
6 changed files with 134 additions and 56 deletions

View File

@@ -57,6 +57,14 @@ public class JedisTest extends JedisCommandTestBase {
jedis.hmget("foobar", "foo");
}
@Test(expected = JedisConnectionException.class)
public void timeoutConnectionWithURI() throws Exception {
jedis = new Jedis(new URI("redis://:foobared@localhost:6380/2"), 15000);
jedis.configSet("timeout", "1");
Thread.sleep(2000);
jedis.hmget("foobar", "foo");
}
@Test(expected = JedisDataException.class)
public void failWhenSendingNullValues() {
jedis.set("foo", null);
@@ -92,7 +100,15 @@ public class JedisTest extends JedisCommandTestBase {
assertEquals("PONG", jedis.ping());
assertEquals("bar", jedis.get("foo"));
}
@Test
public void allowUrlWithNoDBAndNoPassword() {
Jedis jedis = new Jedis("redis://localhost:6380");
assertEquals(jedis.getClient().getHost(), "localhost");
assertEquals(jedis.getClient().getPort(), 6380);
assertEquals(jedis.getDB(), (Long) 0L);
}
@Test
public void checkCloseable() {
jedis.close();