Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>2.1.0.BUILD-SNAPSHOT</version>
<version>2.1.0.DATAREDIS-765-SNAPSHOT</version>

<name>Spring Data Redis</name>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,12 @@ public void setTimeout(int timeout) {
* @return the use of connection pooling.
*/
public boolean getUsePool() {

// Jedis Sentinel cannot operate without a pool.
if (isRedisSentinelAware()) {
return true;
}

return clientConfiguration.isUsePooling();
}

Expand All @@ -669,9 +675,16 @@ public boolean getUsePool() {
* @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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
*/
package org.springframework.data.redis.connection.jedis;

import static org.hamcrest.core.IsEqual.*;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisSentinelConfiguration;
import org.springframework.data.redis.test.util.RedisSentinelRule;

Expand All @@ -47,7 +48,7 @@ public void tearDown() {
}
}

@Test // DATAREDIS-574
@Test // DATAREDIS-574, DATAREDIS-765
public void shouldInitializeWithSentinelConfiguration() {

JedisClientConfiguration clientConfiguration = JedisClientConfiguration.builder() //
Expand All @@ -57,7 +58,10 @@ public void shouldInitializeWithSentinelConfiguration() {
factory = new JedisConnectionFactory(SENTINEL_CONFIG, clientConfiguration);
factory.afterPropertiesSet();

assertThat(factory.getConnection().getClientName(), equalTo("clientName"));
RedisConnection connection = factory.getConnection();

assertThat(factory.getUsePool(), is(true));
assertThat(connection.getClientName(), equalTo("clientName"));
}

@Test // DATAREDIS-324
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ public void shouldInitJedisPoolWhenNoSentinelConfigPresent() {
verify(connectionFactory, never()).createRedisSentinelPool(any(RedisSentinelConfiguration.class));
}

@Test(expected = IllegalStateException.class) // DATAREDIS-765
public void shouldRejectPoolDisablingWhenSentinelConfigPresent() {

connectionFactory = new JedisConnectionFactory(new RedisSentinelConfiguration());

connectionFactory.setUsePool(false);
}

@Test // DATAREDIS-315
public void shouldInitConnectionCorrectlyWhenClusterConfigPresent() {

Expand Down