DATAREDIS-508 - Support lettuce Pub/Sub when using Redis Cluster.
We now use Lettuce's Redis Cluster Pub/Sub connection to create Pub/Sub connections in a cluster.
This commit is contained in:
committed by
Christoph Strobl
parent
36f680ff5b
commit
12b030b1f7
@@ -22,9 +22,9 @@ import io.lettuce.core.cluster.RedisClusterClient;
|
||||
import io.lettuce.core.cluster.SlotHash;
|
||||
import io.lettuce.core.cluster.api.StatefulRedisClusterConnection;
|
||||
import io.lettuce.core.cluster.api.sync.RedisClusterCommands;
|
||||
import io.lettuce.core.cluster.models.partitions.Partitions;
|
||||
import io.lettuce.core.codec.ByteArrayCodec;
|
||||
import io.lettuce.core.codec.RedisCodec;
|
||||
import io.lettuce.core.pubsub.StatefulRedisPubSubConnection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -35,7 +35,6 @@ import java.util.Set;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
@@ -101,9 +100,9 @@ public class LettuceClusterConnection extends LettuceConnection implements Defau
|
||||
Assert.notNull(executor, "ClusterCommandExecutor must not be null.");
|
||||
|
||||
this.clusterClient = clusterClient;
|
||||
topologyProvider = new LettuceClusterTopologyProvider(clusterClient);
|
||||
clusterCommandExecutor = executor;
|
||||
disposeClusterCommandExecutorOnClose = false;
|
||||
this.topologyProvider = new LettuceClusterTopologyProvider(clusterClient);
|
||||
this.clusterCommandExecutor = executor;
|
||||
this.disposeClusterCommandExecutorOnClose = false;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -224,9 +223,7 @@ public class LettuceClusterConnection extends LettuceConnection implements Defau
|
||||
@Override
|
||||
public RedisClusterNode clusterGetNodeForSlot(int slot) {
|
||||
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(clusterClient);
|
||||
return LettuceConverters
|
||||
.toRedisClusterNode(((Partitions) accessor.getPropertyValue("partitions")).getPartitionBySlot(slot));
|
||||
return LettuceConverters.toRedisClusterNode(clusterClient.getPartitions().getPartitionBySlot(slot));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -518,6 +515,19 @@ public class LettuceClusterConnection extends LettuceConnection implements Defau
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.lettuce.LettuceConnection#switchToPubSub()
|
||||
*/
|
||||
@Override
|
||||
protected StatefulRedisPubSubConnection<byte[], byte[]> switchToPubSub() {
|
||||
|
||||
close();
|
||||
|
||||
// open a pubsub one
|
||||
return clusterClient.connectPubSub(CODEC);
|
||||
}
|
||||
|
||||
public ClusterCommandExecutor getClusterCommandExecutor() {
|
||||
return clusterCommandExecutor;
|
||||
}
|
||||
|
||||
@@ -798,11 +798,10 @@ public class LettuceConnection extends AbstractRedisConnection {
|
||||
}
|
||||
}
|
||||
|
||||
private StatefulRedisPubSubConnection<byte[], byte[]> switchToPubSub() {
|
||||
protected StatefulRedisPubSubConnection<byte[], byte[]> switchToPubSub() {
|
||||
|
||||
close();
|
||||
// open a pubsub one
|
||||
return ((RedisClient) client).connectPubSub(CODEC);
|
||||
// return ((RedisClient) client).connectPubSub(CODEC);
|
||||
}
|
||||
|
||||
void pipeline(LettuceResult result) {
|
||||
@@ -892,7 +891,6 @@ public class LettuceConnection extends AbstractRedisConnection {
|
||||
((StatefulRedisConnection<byte[], byte[]>) asyncDedicatedConn).sync().select(dbIndex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (asyncDedicatedConn instanceof StatefulRedisConnection) {
|
||||
|
||||
Reference in New Issue
Block a user