DATAREDIS-775 - Expose Lettuce RedisClient through RedisClientProvider.

We now expose the underlying Redis Client instance via RedisClientProvider.getRedisClient() to components that require direct client interaction. The client is exposed through ClusterConnectionProvider and now also through LettucePoolingConnectionProvider.

Exposing the client via LettucePoolingConnectionProvider allows Redis Cluster usage with connection pooling.

Original Pull Request: #316
This commit is contained in:
Mark Paluch
2018-02-27 11:32:19 +01:00
committed by Christoph Strobl
parent 997afadc23
commit 0b60d632cc
6 changed files with 114 additions and 12 deletions

View File

@@ -28,6 +28,7 @@ import io.lettuce.core.cluster.RedisClusterClient;
import io.lettuce.core.cluster.api.sync.RedisAdvancedClusterCommands;
import java.nio.charset.Charset;
import java.time.Duration;
import java.util.*;
import java.util.concurrent.TimeUnit;
@@ -41,16 +42,10 @@ import org.springframework.data.geo.Circle;
import org.springframework.data.geo.Distance;
import org.springframework.data.geo.GeoResults;
import org.springframework.data.geo.Point;
import org.springframework.data.redis.connection.ClusterConnectionTests;
import org.springframework.data.redis.connection.ClusterSlotHashUtil;
import org.springframework.data.redis.connection.DataType;
import org.springframework.data.redis.connection.DefaultSortParameters;
import org.springframework.data.redis.connection.DefaultTuple;
import org.springframework.data.redis.connection.RedisClusterNode;
import org.springframework.data.redis.connection.*;
import org.springframework.data.redis.connection.RedisClusterNode.SlotRange;
import org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation;
import org.springframework.data.redis.connection.RedisListCommands.Position;
import org.springframework.data.redis.connection.RedisNode;
import org.springframework.data.redis.connection.RedisStringCommands.BitOperation;
import org.springframework.data.redis.connection.RedisStringCommands.SetOption;
import org.springframework.data.redis.connection.RedisZSetCommands.Range;
@@ -121,6 +116,47 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
client.shutdown(0, 0, TimeUnit.MILLISECONDS);
}
@Test // DATAREDIS-775
public void shouldCreateConnectionWithPooling() {
LettuceConnectionFactory factory = createConnectionFactory();
factory.afterPropertiesSet();
RedisConnection connection = factory.getConnection();
assertThat(connection.ping(), is("PONG"));
connection.close();
factory.destroy();
}
@Test // DATAREDIS-775
public void shouldCreateClusterConnectionWithPooling() {
LettuceConnectionFactory factory = createConnectionFactory();
factory.afterPropertiesSet();
RedisClusterConnection clusterConnection = factory.getClusterConnection();
assertThat(clusterConnection.ping(ClusterTestVariables.CLUSTER_NODE_1), is("PONG"));
clusterConnection.close();
factory.destroy();
}
private static LettuceConnectionFactory createConnectionFactory() {
LettucePoolingClientConfiguration clientConfiguration = LettucePoolingClientConfiguration.builder() //
.clientResources(LettuceTestClientResources.getSharedClientResources()) //
.shutdownTimeout(Duration.ZERO) //
.build();
RedisClusterConfiguration clusterConfiguration = new RedisClusterConfiguration();
clusterConfiguration.addClusterNode(ClusterTestVariables.CLUSTER_NODE_1);
return new LettuceConnectionFactory(clusterConfiguration, clientConfiguration);
}
@Test // DATAREDIS-315
public void appendShouldAddValueCorrectly() {

View File

@@ -17,6 +17,7 @@ package org.springframework.data.redis.connection.lettuce;
import io.lettuce.core.api.StatefulRedisConnection;
import io.lettuce.core.api.sync.RedisCommands;
import io.lettuce.core.cluster.RedisClusterClient;
import io.lettuce.core.cluster.api.StatefulRedisClusterConnection;
import io.lettuce.core.cluster.api.sync.RedisAdvancedClusterCommands;
import io.lettuce.core.cluster.api.sync.RedisClusterCommands;
@@ -122,7 +123,7 @@ public abstract class LettuceReactiveCommandsTestsBase {
ClusterConnectionProvider clusterConnectionProvider = (ClusterConnectionProvider) nativeConnectionProvider;
nativeCommands = nativeConnectionProvider.getConnection(StatefulRedisClusterConnection.class).sync();
this.connection = new LettuceReactiveRedisClusterConnection(connectionProvider,
clusterConnectionProvider.getClient());
(RedisClusterClient) clusterConnectionProvider.getRedisClient());
}
}