Skip to content

Commit

Permalink
Add ShardedJedisPoolConfig (#3009)
Browse files Browse the repository at this point in the history
  • Loading branch information
sazzad16 authored May 29, 2022
1 parent c2022a0 commit c03d71f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
13 changes: 13 additions & 0 deletions src/main/java/redis/clients/jedis/ShardedJedisPoolConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package redis.clients.jedis;

import org.apache.commons.pool2.impl.GenericObjectPoolConfig;

public class ShardedJedisPoolConfig extends GenericObjectPoolConfig<ShardedJedis> {
public ShardedJedisPoolConfig() {
// defaults to make your life with connection pool easier :)
setTestWhileIdle(true);
setMinEvictableIdleTimeMillis(60000);
setTimeBetweenEvictionRunsMillis(30000);
setNumTestsPerEvictionRun(-1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import redis.clients.jedis.ShardedJedis;
import redis.clients.jedis.ShardedJedisPipeline;
import redis.clients.jedis.ShardedJedisPool;
import redis.clients.jedis.ShardedJedisPoolConfig;
import redis.clients.jedis.exceptions.JedisExhaustedPoolException;
import redis.clients.jedis.util.Hashing;

Expand Down Expand Up @@ -70,8 +71,7 @@ public void checkCloseableConnections() throws Exception {

@Test
public void checkConnectionWithDefaultPort() {
ShardedJedisPool pool = new ShardedJedisPool(new GenericObjectPoolConfig<ShardedJedis>(),
shards);
ShardedJedisPool pool = new ShardedJedisPool(new ShardedJedisPoolConfig(), shards);
ShardedJedis jedis = pool.getResource();
jedis.set("foo", "bar");
assertEquals("bar", jedis.get("foo"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
* This test is only executed when the server/cluster is Redis 6. or more.
*/
public class ShardedJedisPoolWithCompleteCredentialsTest {
private static HostAndPort hnp = HostAndPortUtil.getRedisServers().get(0);
private static HostAndPort redis1 = HostAndPortUtil.getRedisServers().get(0);
private static HostAndPort redis2 = HostAndPortUtil.getRedisServers().get(1);

Expand Down Expand Up @@ -76,8 +75,7 @@ public void checkCloseableConnections() throws Exception {

@Test
public void checkConnectionWithDefaultPort() {
ShardedJedisPool pool = new ShardedJedisPool(new GenericObjectPoolConfig<ShardedJedis>(),
shards);
ShardedJedisPool pool = new ShardedJedisPool(new ShardedJedisPoolConfig(), shards);
ShardedJedis jedis = pool.getResource();
jedis.set("foo", "bar");
assertEquals("bar", jedis.get("foo"));
Expand Down

0 comments on commit c03d71f

Please sign in to comment.