Merge pull request #197 from michaelcameron/jedis
--- We would like to add the ability to specify the database number on the pool config. We have a number of integration/functional tests in different projects using redis and would like to keep them separate. Setting up a number of redis server instances on different ports would become unwieldy. The changes add the ability to specify the database number for jedis pools with associated test. I did not add the ability to create a raw jedis connection with a database number because the current implementation of pool creates the jedis object first, then if a password exists it calls the auth command. However, if a password is required, then the select command on the jedis create would fail. I also did not change the shard constructor of jedis to use a database number (which actually does have the constructor of jedis call the auth command). I could clean up the implementation to always have the jedis constructor call auth if a password exists, then select the database if it is non-zero, and changing sharding info to contain a database config value. Let me know if you want me to make these bigger changes.
This commit is contained in:
@@ -95,4 +95,22 @@ public class JedisPoolTest extends Assert {
|
||||
pool.returnResource(jedis);
|
||||
pool.destroy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nonDefaultDatabase() {
|
||||
JedisPool pool0 = new JedisPool(new JedisPoolConfig(), hnp.host,
|
||||
hnp.port, 2000, "foobared");
|
||||
Jedis jedis0 = pool0.getResource();
|
||||
jedis0.set("foo", "bar");
|
||||
assertEquals( "bar", jedis0.get("foo") );
|
||||
pool0.returnResource(jedis0);
|
||||
pool0.destroy();
|
||||
|
||||
JedisPool pool1 = new JedisPool(new JedisPoolConfig(), hnp.host,
|
||||
hnp.port, 2000, "foobared", 1);
|
||||
Jedis jedis1 = pool1.getResource();
|
||||
assertNull( jedis1.get("foo") );
|
||||
pool1.returnResource(jedis0);
|
||||
pool1.destroy();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user