DATAREDIS-714 - Use Jedis API for database selection.

We now rely more on Jedis to select the appropriate Redis database and we no longer select the database when opening/closing a connection. Previously, we always reset the database if a database index greater zero was configured.
A properly configured Jedis pool ensures that the appropriate database is selected even if the database was selected during connection interaction.

Relying on Jedis reduces the number of issued SELECT commands and improves that way overall performance when executing commands via the Template API.

Original Pull Request: #291
This commit is contained in:
Mark Paluch
2017-11-02 15:00:38 +01:00
committed by Christoph Strobl
parent d8ec35f48b
commit aa4d784df0
3 changed files with 16 additions and 20 deletions

View File

@@ -36,6 +36,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.redis.RedisConnectionFailureException;
import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.connection.AbstractConnectionIntegrationTests;
import org.springframework.data.redis.connection.ConnectionUtils;
@@ -113,13 +114,18 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati
factory2.destroy();
}
@Test(expected = InvalidDataAccessApiUsageException.class)
@Test(expected = RedisConnectionFailureException.class) // DATAREDIS-714
public void testCreateConnectionWithDbFailure() {
JedisConnectionFactory factory2 = new JedisConnectionFactory();
factory2.setDatabase(77);
factory2.afterPropertiesSet();
factory2.getConnection();
factory2.destroy();
try {
factory2.getConnection();
} finally {
factory2.destroy();
}
}
@Test
@@ -381,8 +387,8 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati
@RequiresRedisSentinel(SentinelsAvailable.ONE_ACTIVE)
public void shouldReturnSentinelCommandsWhenWhenActiveSentinelFound() {
((JedisConnection) byteConnection).setSentinelConfiguration(new RedisSentinelConfiguration().master("mymaster")
.sentinel("127.0.0.1", 26379).sentinel("127.0.0.1", 26380));
((JedisConnection) byteConnection).setSentinelConfiguration(
new RedisSentinelConfiguration().master("mymaster").sentinel("127.0.0.1", 26379).sentinel("127.0.0.1", 26380));
assertThat(connection.getSentinelConnection(), notNullValue());
}