Added password to Jedis, JedisPool and ShardedJedis constructor for easier and more efficient usage

This commit is contained in:
Jonathan Leibiusky
2010-09-14 16:43:48 -03:00
parent 708ae8a56e
commit 224555afd2
6 changed files with 53 additions and 21 deletions

View File

@@ -13,12 +13,12 @@ import redis.clients.jedis.Protocol;
public class JedisPoolTest extends Assert {
@Test
public void checkConnections() throws TimeoutException {
JedisPool pool = new JedisPool("localhost", Protocol.DEFAULT_PORT, 2000);
JedisPool pool = new JedisPool("localhost", Protocol.DEFAULT_PORT,
2000, "foobared");
pool.setResourcesNumber(10);
pool.init();
Jedis jedis = pool.getResource(200);
jedis.auth("foobared");
jedis.set("foo", "bar");
assertEquals("bar", jedis.get("foo"));
pool.returnResource(jedis);
@@ -27,12 +27,12 @@ public class JedisPoolTest extends Assert {
@Test
public void checkConnectionWithDefaultPort() throws TimeoutException {
JedisPool pool = new JedisPool("localhost");
JedisPool pool = new JedisPool("localhost", Protocol.DEFAULT_PORT,
2000, "foobared");
pool.setResourcesNumber(10);
pool.init();
Jedis jedis = pool.getResource(200);
jedis.auth("foobared");
jedis.set("foo", "bar");
assertEquals("bar", jedis.get("foo"));
pool.returnResource(jedis);
@@ -41,17 +41,16 @@ public class JedisPoolTest extends Assert {
@Test
public void checkJedisIsReusedWhenReturned() throws TimeoutException {
JedisPool pool = new JedisPool("localhost");
JedisPool pool = new JedisPool("localhost", Protocol.DEFAULT_PORT,
2000, "foobared");
pool.setResourcesNumber(1);
pool.init();
Jedis jedis = pool.getResource(200);
jedis.auth("foobared");
jedis.set("foo", "0");
pool.returnResource(jedis);
jedis = pool.getResource(200);
jedis.auth("foobared");
jedis.incr("foo");
pool.returnResource(jedis);
pool.destroy();
@@ -60,17 +59,16 @@ public class JedisPoolTest extends Assert {
@Test
public void checkPoolRepairedWhenJedisIsBroken() throws TimeoutException,
IOException {
JedisPool pool = new JedisPool("localhost");
JedisPool pool = new JedisPool("localhost", Protocol.DEFAULT_PORT,
2000, "foobared");
pool.setResourcesNumber(1);
pool.init();
Jedis jedis = pool.getResource(200);
jedis.auth("foobared");
jedis.quit();
pool.returnBrokenResource(jedis);
jedis = pool.getResource(200);
jedis.auth("foobared");
jedis.incr("foo");
pool.returnResource(jedis);
pool.destroy();
@@ -78,16 +76,15 @@ public class JedisPoolTest extends Assert {
@Test(expected = TimeoutException.class)
public void checkPoolOverflow() throws TimeoutException {
JedisPool pool = new JedisPool("localhost");
JedisPool pool = new JedisPool("localhost", Protocol.DEFAULT_PORT,
2000, "foobared");
pool.setResourcesNumber(1);
pool.init();
Jedis jedis = pool.getResource(200);
jedis.auth("foobared");
jedis.set("foo", "0");
Jedis newJedis = pool.getResource(200);
newJedis.auth("foobared");
newJedis.incr("foo");
}
}