DATAREDIS-1093 - Document that Master/Replica connections do not support Pub/Sub.
This commit is contained in:
@@ -133,7 +133,7 @@ class WriteToMasterReadFromReplicaConfiguration {
|
||||
}
|
||||
----
|
||||
|
||||
TIP: For environments reporting non-public addresses through the `INFO` command (for example, when using AWS), use `RedisStaticMasterReplicaConfiguration` instead of `RedisStandaloneConfiguration`.
|
||||
TIP: For environments reporting non-public addresses through the `INFO` command (for example, when using AWS), use `RedisStaticMasterReplicaConfiguration` instead of `RedisStandaloneConfiguration`. Please note that `RedisStaticMasterReplicaConfiguration` does not support Pub/Sub because of missing Pub/Sub message propagation across individual servers.
|
||||
|
||||
[[redis:sentinel]]
|
||||
== Redis Sentinel Support
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.springframework.util.Assert;
|
||||
* Master / Replica configuration to nodes know to not change address. Eg. when connecting to
|
||||
* <a href="https://aws.amazon.com/documentation/elasticache/">AWS ElastiCache with Read Replicas</a>. <br/>
|
||||
* Note: Redis is undergoing a nomenclature change where the term replica is used synonymously to slave.
|
||||
* Please also note that a Master/Replica connection cannot be used for Pub/Sub operations.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
|
||||
@@ -22,6 +22,7 @@ import io.lettuce.core.api.StatefulConnection;
|
||||
import io.lettuce.core.codec.RedisCodec;
|
||||
import io.lettuce.core.masterslave.MasterSlave;
|
||||
import io.lettuce.core.masterslave.StatefulRedisMasterSlaveConnection;
|
||||
import io.lettuce.core.pubsub.StatefulRedisPubSubConnection;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
@@ -68,6 +69,10 @@ class StaticMasterReplicaConnectionProvider implements LettuceConnectionProvider
|
||||
@Override
|
||||
public <T extends StatefulConnection<?, ?>> T getConnection(Class<T> connectionType) {
|
||||
|
||||
if (connectionType.equals(StatefulRedisPubSubConnection.class)) {
|
||||
throw new UnsupportedOperationException("Pub/Sub connections not supported with Master/Replica configurations");
|
||||
}
|
||||
|
||||
if (StatefulConnection.class.isAssignableFrom(connectionType)) {
|
||||
|
||||
// See https://github.com/lettuce-io/lettuce-core/issues/845 for MasterSlave -> MasterReplica change.
|
||||
|
||||
@@ -475,6 +475,28 @@ public class LettuceConnectionFactoryTests {
|
||||
factory.destroy();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-1093
|
||||
public void pubSubDoesNotSupportMasterReplicaConnections() {
|
||||
|
||||
assumeTrue(String.format("No replicas connected to %s:%s.", SettingsUtils.getHost(), SettingsUtils.getPort()),
|
||||
connection.info("replication").getProperty("connected_slaves", "0").compareTo("0") > 0);
|
||||
|
||||
RedisStaticMasterReplicaConfiguration elastiCache = new RedisStaticMasterReplicaConfiguration(
|
||||
SettingsUtils.getHost()).node(SettingsUtils.getHost(), SettingsUtils.getPort() + 1);
|
||||
|
||||
LettuceConnectionFactory factory = new LettuceConnectionFactory(elastiCache);
|
||||
factory.setClientResources(LettuceTestClientResources.getSharedClientResources());
|
||||
factory.afterPropertiesSet();
|
||||
|
||||
RedisConnection connection = factory.getConnection();
|
||||
|
||||
assertThatThrownBy(() -> connection.pSubscribe((message, pattern) -> {
|
||||
}, "foo".getBytes())).isInstanceOf(RedisSystemException.class).hasCauseInstanceOf(UnsupportedOperationException.class);
|
||||
|
||||
connection.close();
|
||||
factory.destroy();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-762, DATAREDIS-869
|
||||
public void factoryUsesElastiCacheMasterWithoutMaster() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user