DATAREDIS-790 - 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.
Original ticket: DATAREDIS-714.
This commit is contained in:
Mark Paluch
2017-11-02 15:00:38 +01:00
parent f10418f526
commit 99b18c4ca5
3 changed files with 19 additions and 23 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2011-2017 the original author or authors.
* Copyright 2011-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,6 +34,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;
@@ -55,7 +56,7 @@ import redis.clients.jedis.JedisPoolConfig;
/**
* Integration test of {@link JedisConnection}
*
*
* @author Costin Leau
* @author Jennifer Hickey
* @author Thomas Darimont
@@ -113,13 +114,18 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati
factory2.destroy();
}
@Test(expected = InvalidDataAccessApiUsageException.class)
@Test(expected = RedisConnectionFailureException.class) // DATAREDIS-714, DATAREDIS-790
public void testCreateConnectionWithDbFailure() {
JedisConnectionFactory factory2 = new JedisConnectionFactory();
factory2.setDatabase(77);
factory2.afterPropertiesSet();
factory2.getConnection();
factory2.destroy();
try {
factory2.getConnection();
} finally {
factory2.destroy();
}
}
@Test
@@ -385,8 +391,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());
}