diff --git a/src/main/java/redis/clients/jedis/JedisPool.java b/src/main/java/redis/clients/jedis/JedisPool.java index e07896e732..86699e990e 100644 --- a/src/main/java/redis/clients/jedis/JedisPool.java +++ b/src/main/java/redis/clients/jedis/JedisPool.java @@ -224,7 +224,7 @@ public JedisPool(final GenericObjectPoolConfig poolConfig, final String h final int connectionTimeout, final int soTimeout, final String password, final int database, final String clientName, final boolean ssl, final SSLSocketFactory sslSocketFactory, final SSLParameters sslParameters, final HostnameVerifier hostnameVerifier) { - super(poolConfig, new JedisFactory(host, port, connectionTimeout, soTimeout, password, + this(poolConfig, new JedisFactory(host, port, connectionTimeout, soTimeout, password, database, clientName, ssl, sslSocketFactory, sslParameters, hostnameVerifier)); } @@ -251,19 +251,23 @@ public JedisPool(final GenericObjectPoolConfig poolConfig, final String h final String user, final String password, final int database, final String clientName, final boolean ssl, final SSLSocketFactory sslSocketFactory, final SSLParameters sslParameters, final HostnameVerifier hostnameVerifier) { - super(poolConfig, new JedisFactory(host, port, connectionTimeout, soTimeout, infiniteSoTimeout, + this(poolConfig, new JedisFactory(host, port, connectionTimeout, soTimeout, infiniteSoTimeout, user, password, database, clientName, ssl, sslSocketFactory, sslParameters, hostnameVerifier)); } + public JedisPool(final HostAndPort hostAndPort, final JedisClientConfig clientConfig) { + this(new GenericObjectPoolConfig(), hostAndPort, clientConfig); + } + public JedisPool(final GenericObjectPoolConfig poolConfig, final HostAndPort hostAndPort, final JedisClientConfig clientConfig) { - super(poolConfig, new JedisFactory(hostAndPort, clientConfig)); + this(poolConfig, new JedisFactory(hostAndPort, clientConfig)); } public JedisPool(final GenericObjectPoolConfig poolConfig, final JedisSocketFactory jedisSocketFactory, final JedisClientConfig clientConfig) { - super(poolConfig, new JedisFactory(jedisSocketFactory, clientConfig)); + this(poolConfig, new JedisFactory(jedisSocketFactory, clientConfig)); } public JedisPool(final GenericObjectPoolConfig poolConfig) { @@ -277,21 +281,21 @@ public JedisPool(final String host, final int port, final boolean ssl) { public JedisPool(final GenericObjectPoolConfig poolConfig, final String host, int port, final int connectionTimeout, final int soTimeout, final String password, final int database, final String clientName) { - super(poolConfig, new JedisFactory(host, port, connectionTimeout, soTimeout, password, + this(poolConfig, new JedisFactory(host, port, connectionTimeout, soTimeout, password, database, clientName)); } public JedisPool(final GenericObjectPoolConfig poolConfig, final String host, int port, final int connectionTimeout, final int soTimeout, final String user, final String password, final int database, final String clientName) { - super(poolConfig, new JedisFactory(host, port, connectionTimeout, soTimeout, user, password, + this(poolConfig, new JedisFactory(host, port, connectionTimeout, soTimeout, user, password, database, clientName)); } public JedisPool(final GenericObjectPoolConfig poolConfig, final String host, int port, final int connectionTimeout, final int soTimeout, final int infiniteSoTimeout, final String user, final String password, final int database, final String clientName) { - super(poolConfig, new JedisFactory(host, port, connectionTimeout, soTimeout, infiniteSoTimeout, + this(poolConfig, new JedisFactory(host, port, connectionTimeout, soTimeout, infiniteSoTimeout, user, password, database, clientName)); } @@ -345,7 +349,7 @@ public JedisPool(final GenericObjectPoolConfig poolConfig, final URI uri, public JedisPool(final GenericObjectPoolConfig poolConfig, final URI uri, final int connectionTimeout, final int soTimeout, final SSLSocketFactory sslSocketFactory, final SSLParameters sslParameters, final HostnameVerifier hostnameVerifier) { - super(poolConfig, new JedisFactory(uri, connectionTimeout, soTimeout, null, sslSocketFactory, + this(poolConfig, new JedisFactory(uri, connectionTimeout, soTimeout, null, sslSocketFactory, sslParameters, hostnameVerifier)); } @@ -353,7 +357,7 @@ public JedisPool(final GenericObjectPoolConfig poolConfig, final URI uri, final int connectionTimeout, final int soTimeout, final int infiniteSoTimeout, final SSLSocketFactory sslSocketFactory, final SSLParameters sslParameters, final HostnameVerifier hostnameVerifier) { - super(poolConfig, new JedisFactory(uri, connectionTimeout, soTimeout, infiniteSoTimeout, null, + this(poolConfig, new JedisFactory(uri, connectionTimeout, soTimeout, infiniteSoTimeout, null, sslSocketFactory, sslParameters, hostnameVerifier)); } diff --git a/src/main/java/redis/clients/jedis/JedisSentinelPool.java b/src/main/java/redis/clients/jedis/JedisSentinelPool.java index b846c6a782..5d8ff75d0e 100644 --- a/src/main/java/redis/clients/jedis/JedisSentinelPool.java +++ b/src/main/java/redis/clients/jedis/JedisSentinelPool.java @@ -187,6 +187,11 @@ public JedisSentinelPool(String masterName, Set sentinels, DefaultJedisClientConfig.builder().build()); } + public JedisSentinelPool(String masterName, Set sentinels, + final JedisClientConfig masteClientConfig, final JedisClientConfig sentinelClientConfig) { + this(masterName, sentinels, new GenericObjectPoolConfig(), masteClientConfig, sentinelClientConfig); + } + public JedisSentinelPool(String masterName, Set sentinels, final GenericObjectPoolConfig poolConfig, final JedisClientConfig masteClientConfig, final JedisClientConfig sentinelClientConfig) { diff --git a/src/test/java/redis/clients/jedis/tests/JedisPoolTest.java b/src/test/java/redis/clients/jedis/tests/JedisPoolTest.java index 39777884be..6296d6299e 100644 --- a/src/test/java/redis/clients/jedis/tests/JedisPoolTest.java +++ b/src/test/java/redis/clients/jedis/tests/JedisPoolTest.java @@ -15,6 +15,7 @@ import org.apache.commons.pool2.impl.GenericObjectPoolConfig; import org.junit.Test; +import redis.clients.jedis.DefaultJedisClientConfig; import redis.clients.jedis.HostAndPort; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisFactory; @@ -40,6 +41,19 @@ public void checkConnections() { assertTrue(pool.isClosed()); } + @Test + public void checkResourceWithConfig() { + try (JedisPool pool = new JedisPool(HostAndPortUtil.getRedisServers().get(7), + DefaultJedisClientConfig.builder().socketTimeoutMillis(5000).build())) { + + try (Jedis jedis = pool.getResource()) { + assertEquals("PONG", jedis.ping()); + assertEquals(5000, jedis.getClient().getSoTimeout()); + jedis.close(); + } + } + } + @Test public void checkCloseableConnections() throws Exception { JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort(), 2000); diff --git a/src/test/java/redis/clients/jedis/tests/SSLJedisSentinelPoolTest.java b/src/test/java/redis/clients/jedis/tests/SSLJedisSentinelPoolTest.java index 185994fd11..a43b095376 100644 --- a/src/test/java/redis/clients/jedis/tests/SSLJedisSentinelPoolTest.java +++ b/src/test/java/redis/clients/jedis/tests/SSLJedisSentinelPoolTest.java @@ -1,10 +1,10 @@ package redis.clients.jedis.tests; +import java.util.HashSet; +import java.util.Set; import org.apache.commons.pool2.impl.GenericObjectPoolConfig; import org.junit.BeforeClass; import org.junit.Test; -import java.util.HashSet; -import java.util.Set; import redis.clients.jedis.DefaultJedisClientConfig; import redis.clients.jedis.HostAndPort; @@ -38,6 +38,9 @@ public void sentinelWithoutSslConnectsToRedisWithSsl() { .hostAndPortMapper(SSL_PORT_MAPPER).build(); DefaultJedisClientConfig sentinelConfig = DefaultJedisClientConfig.builder() .clientName("sentinel-client").ssl(false).build(); + try (JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, masterConfig, sentinelConfig)) { + pool.getResource().close(); + } try (JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, POOL_CONFIG, masterConfig, sentinelConfig)) { pool.getResource().close(); @@ -50,6 +53,9 @@ public void sentinelWithSslConnectsToRedisWithoutSsl() { .password("foobared").clientName("sentinel-master-client").ssl(false).build(); DefaultJedisClientConfig sentinelConfig = DefaultJedisClientConfig.builder() .clientName("sentinel-client").ssl(true).hostAndPortMapper(SSL_PORT_MAPPER).build(); + try (JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, masterConfig, sentinelConfig)) { + pool.getResource().close(); + } try (JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, POOL_CONFIG, masterConfig, sentinelConfig)) { pool.getResource().close(); @@ -63,6 +69,9 @@ public void sentinelWithSslConnectsToRedisWithSsl() { .hostAndPortMapper(SSL_PORT_MAPPER).build(); DefaultJedisClientConfig sentinelConfig = DefaultJedisClientConfig.builder() .clientName("sentinel-client").ssl(true).hostAndPortMapper(SSL_PORT_MAPPER).build(); + try (JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, masterConfig, sentinelConfig)) { + pool.getResource().close(); + } try (JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, POOL_CONFIG, masterConfig, sentinelConfig)) { pool.getResource().close();