DATAREDIS-765 - Enable pooling when configuring Jedis to use Redis Sentinel.

We now enable pool usage when configuring JedisConnectionFactory with RedisSentinelConfiguration to prevent accidental connections using the non-pooled standalone configuration. Jedis can operate with Sentinel only with pooling.

We also reject calls to disable pooling when JedisConnectionFactory is configured to use Sentinel.

Original Pull request: #307
This commit is contained in:
Mark Paluch
2018-01-31 12:59:26 +01:00
committed by Christoph Strobl
parent 2fe048bfff
commit b1f6bc7698
3 changed files with 28 additions and 3 deletions

View File

@@ -660,6 +660,12 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean,
* @return the use of connection pooling.
*/
public boolean getUsePool() {
// Jedis Sentinel cannot operate without a pool.
if (isRedisSentinelAware()) {
return true;
}
return clientConfiguration.isUsePooling();
}
@@ -669,9 +675,16 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean,
* @param usePool the usePool to set.
* @deprecated since 2.0, configure pooling usage with {@link JedisClientConfiguration}.
* @throws IllegalStateException if {@link JedisClientConfiguration} is immutable.
* @throws IllegalStateException if configured to use sentinel and {@code usePool} is {@literal false} as Jedis
* requires pooling for Redis sentinel use.
*/
@Deprecated
public void setUsePool(boolean usePool) {
if (isRedisSentinelAware() && !usePool) {
throw new IllegalStateException("Jedis requires pooling for Redis Sentinel use!");
}
getMutableConfiguration().setUsePooling(usePool);
}