DATAREDIS-576 - Support client name for Redis connections using Lettuce.
We now allow configuration of the client name that is applied to connections using the Lettuce driver.
LettuceClientConfiguration configuration = LettuceClientConfiguration.builder().clientName("foo-bar").build();
LettuceConnectionFactory factory = new LettuceConnectionFactory(new RedisStandaloneConfiguration(), configuration);
Fixed some typos, javadoc and method visibility along the way.
Original Pull Request: #285
This commit is contained in:
committed by
Christoph Strobl
parent
1d528f03f2
commit
5059887a76
@@ -48,7 +48,7 @@ public class JedisConnectionFactorySentinelIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-574
|
||||
public void shouldInitiaizeWithSentinelConfiguration() {
|
||||
public void shouldInitializeWithSentinelConfiguration() {
|
||||
|
||||
JedisClientConfiguration clientConfiguration = JedisClientConfiguration.builder() //
|
||||
.clientName("clientName") //
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.junit.Test;
|
||||
*/
|
||||
public class LettuceClientConfigurationUnitTests {
|
||||
|
||||
@Test // DATAREDIS-574, DATAREDIS-667
|
||||
@Test // DATAREDIS-574, DATAREDIS-576, DATAREDIS-667
|
||||
public void shouldCreateEmptyConfiguration() {
|
||||
|
||||
LettuceClientConfiguration configuration = LettuceClientConfiguration.defaultConfiguration();
|
||||
@@ -42,11 +42,12 @@ public class LettuceClientConfigurationUnitTests {
|
||||
assertThat(configuration.isStartTls()).isFalse();
|
||||
assertThat(configuration.getClientOptions()).isEmpty();
|
||||
assertThat(configuration.getClientResources()).isEmpty();
|
||||
assertThat(configuration.getClientName()).isEmpty();
|
||||
assertThat(configuration.getCommandTimeout()).isEqualTo(Duration.ofSeconds(60));
|
||||
assertThat(configuration.getShutdownTimeout()).isEqualTo(Duration.ofMillis(100));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-574, DATAREDIS-667
|
||||
@Test // DATAREDIS-574, DATAREDIS-576, DATAREDIS-667
|
||||
public void shouldConfigureAllProperties() {
|
||||
|
||||
ClientOptions clientOptions = ClientOptions.create();
|
||||
@@ -58,6 +59,7 @@ public class LettuceClientConfigurationUnitTests {
|
||||
.startTls().and() //
|
||||
.clientOptions(clientOptions) //
|
||||
.clientResources(sharedClientResources) //
|
||||
.clientName("foo") //
|
||||
.commandTimeout(Duration.ofMinutes(5)) //
|
||||
.shutdownTimeout(Duration.ofHours(2)) //
|
||||
.build();
|
||||
@@ -67,6 +69,7 @@ public class LettuceClientConfigurationUnitTests {
|
||||
assertThat(configuration.isStartTls()).isTrue();
|
||||
assertThat(configuration.getClientOptions()).contains(clientOptions);
|
||||
assertThat(configuration.getClientResources()).contains(sharedClientResources);
|
||||
assertThat(configuration.getClientName()).contains("foo");
|
||||
assertThat(configuration.getCommandTimeout()).isEqualTo(Duration.ofMinutes(5));
|
||||
assertThat(configuration.getShutdownTimeout()).isEqualTo(Duration.ofHours(2));
|
||||
}
|
||||
|
||||
@@ -361,4 +361,38 @@ public class LettuceConnectionFactoryTests {
|
||||
|
||||
factory.destroy();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-576
|
||||
public void connectionAppliesClientName() {
|
||||
|
||||
LettuceClientConfiguration configuration = LettuceClientConfiguration.builder()
|
||||
.clientResources(LettuceTestClientResources.getSharedClientResources()).clientName("clientName").build();
|
||||
|
||||
LettuceConnectionFactory factory = new LettuceConnectionFactory(new RedisStandaloneConfiguration(), configuration);
|
||||
factory.setShareNativeConnection(false);
|
||||
factory.afterPropertiesSet();
|
||||
|
||||
RedisConnection connection = factory.getConnection();
|
||||
|
||||
assertThat(connection.getClientName(), is(equalTo("clientName")));
|
||||
connection.close();
|
||||
|
||||
factory.destroy();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-576
|
||||
public void getClientNameShouldEqualWithFactorySetting() {
|
||||
|
||||
LettuceConnectionFactory factory = new LettuceConnectionFactory(new RedisStandaloneConfiguration());
|
||||
factory.setClientResources(LettuceTestClientResources.getSharedClientResources());
|
||||
factory.setClientName("clientName");
|
||||
factory.afterPropertiesSet();
|
||||
|
||||
RedisConnection connection = factory.getConnection();
|
||||
assertThat(connection.getClientName(), equalTo("clientName"));
|
||||
|
||||
connection.close();
|
||||
|
||||
factory.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,8 @@ import org.springframework.data.redis.test.util.MinimumRedisVersionRule;
|
||||
import org.springframework.data.redis.test.util.RedisSentinelRule;
|
||||
|
||||
/**
|
||||
* Integration tests for Lettuce and Redis Sentinel interaction.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
@@ -148,4 +150,24 @@ public class LettuceSentinelIntegrationTests extends AbstractConnectionIntegrati
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-576
|
||||
public void connectionAppliesClientName() {
|
||||
|
||||
LettuceClientConfiguration clientName = LettuceClientConfiguration.builder()
|
||||
.clientResources(LettuceTestClientResources.getSharedClientResources()).clientName("clientName").build();
|
||||
|
||||
LettuceConnectionFactory factory = new LettuceConnectionFactory(SENTINEL_CONFIG, clientName);
|
||||
factory.afterPropertiesSet();
|
||||
|
||||
ConnectionFactoryTracker.add(factory);
|
||||
|
||||
StringRedisConnection connection = new DefaultStringRedisConnection(factory.getConnection());
|
||||
|
||||
try {
|
||||
assertThat(connection.getClientName(), is(equalTo("clientName")));
|
||||
} finally {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user