DATAREDIS-869 - Adapt to nomenclature change about Master/Replica.
We now renamed RedisStaticMasterSlaveConfiguration and StaticMasterSlaveConnectionProvider to RedisStaticMasterReplicaConfiguration respective StaticMasterReplicaConnectionProvider to reflect changes in Redis nomenclature regarding replication. Original Pull Request: #355
This commit is contained in:
committed by
Christoph Strobl
parent
a7352f5612
commit
169b1bd174
@@ -95,10 +95,10 @@ public interface RedisConfiguration {
|
||||
|
||||
/**
|
||||
* @param configuration can be {@literal null}.
|
||||
* @return {@code true} if given {@link RedisConfiguration} is instance of {@link StaticMasterSlaveConfiguration}.
|
||||
* @return {@code true} if given {@link RedisConfiguration} is instance of {@link StaticMasterReplicaConfiguration}.
|
||||
*/
|
||||
static boolean isStaticMasterSlaveConfiguration(@Nullable RedisConfiguration configuration) {
|
||||
return configuration instanceof StaticMasterSlaveConfiguration;
|
||||
static boolean isStaticMasterReplicaConfiguration(@Nullable RedisConfiguration configuration) {
|
||||
return configuration instanceof StaticMasterReplicaConfiguration;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -323,12 +323,14 @@ public interface RedisConfiguration {
|
||||
}
|
||||
|
||||
/**
|
||||
* Configuration interface suitable for Redis master/slave environments with fixed hosts.
|
||||
* Configuration interface suitable for Redis master/slave environments with fixed hosts. <br/>
|
||||
* Redis is undergoing a nomenclature change where the term replica is used synonymously to slave.
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
* @since 2.1
|
||||
*/
|
||||
interface StaticMasterSlaveConfiguration extends WithDatabaseIndex, WithPassword {
|
||||
interface StaticMasterReplicaConfiguration extends WithDatabaseIndex, WithPassword {
|
||||
|
||||
/**
|
||||
* @return unmodifiable {@link List} of {@link RedisStandaloneConfiguration nodes}.
|
||||
|
||||
@@ -19,19 +19,20 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.redis.connection.RedisConfiguration.StaticMasterSlaveConfiguration;
|
||||
import org.springframework.data.redis.connection.RedisConfiguration.StaticMasterReplicaConfiguration;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Configuration class used for setting up {@link RedisConnection} via {@link RedisConnectionFactory} using the provided
|
||||
* Master / Slave 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> .
|
||||
* 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.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
* @since 2.1
|
||||
*/
|
||||
public class RedisStaticMasterSlaveConfiguration implements RedisConfiguration, StaticMasterSlaveConfiguration {
|
||||
public class RedisStaticMasterReplicaConfiguration implements RedisConfiguration, StaticMasterReplicaConfiguration {
|
||||
|
||||
private static final int DEFAULT_PORT = 6379;
|
||||
|
||||
@@ -40,21 +41,21 @@ public class RedisStaticMasterSlaveConfiguration implements RedisConfiguration,
|
||||
private RedisPassword password = RedisPassword.none();
|
||||
|
||||
/**
|
||||
* Create a new {@link StaticMasterSlaveConfiguration} given {@code hostName}.
|
||||
* Create a new {@link StaticMasterReplicaConfiguration} given {@code hostName}.
|
||||
*
|
||||
* @param hostName must not be {@literal null} or empty.
|
||||
*/
|
||||
public RedisStaticMasterSlaveConfiguration(String hostName) {
|
||||
public RedisStaticMasterReplicaConfiguration(String hostName) {
|
||||
this(hostName, DEFAULT_PORT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link StaticMasterSlaveConfiguration} given {@code hostName} and {@code port}.
|
||||
* Create a new {@link StaticMasterReplicaConfiguration} given {@code hostName} and {@code port}.
|
||||
*
|
||||
* @param hostName must not be {@literal null} or empty.
|
||||
* @param port a valid TCP port (1-65535).
|
||||
*/
|
||||
public RedisStaticMasterSlaveConfiguration(String hostName, int port) {
|
||||
public RedisStaticMasterReplicaConfiguration(String hostName, int port) {
|
||||
addNode(hostName, port);
|
||||
}
|
||||
|
||||
@@ -86,9 +87,9 @@ public class RedisStaticMasterSlaveConfiguration implements RedisConfiguration,
|
||||
* Add a {@link RedisStandaloneConfiguration node} to the list of nodes given {@code hostName}.
|
||||
*
|
||||
* @param hostName must not be {@literal null} or empty.
|
||||
* @return {@code this} {@link StaticMasterSlaveConfiguration}.
|
||||
* @return {@code this} {@link StaticMasterReplicaConfiguration}.
|
||||
*/
|
||||
public StaticMasterSlaveConfiguration node(String hostName) {
|
||||
public StaticMasterReplicaConfiguration node(String hostName) {
|
||||
return node(hostName, DEFAULT_PORT);
|
||||
}
|
||||
|
||||
@@ -97,9 +98,9 @@ public class RedisStaticMasterSlaveConfiguration implements RedisConfiguration,
|
||||
*
|
||||
* @param hostName must not be {@literal null} or empty.
|
||||
* @param port a valid TCP port (1-65535).
|
||||
* @return {@code this} {@link StaticMasterSlaveConfiguration}.
|
||||
* @return {@code this} {@link StaticMasterReplicaConfiguration}.
|
||||
*/
|
||||
public RedisStaticMasterSlaveConfiguration node(String hostName, int port) {
|
||||
public RedisStaticMasterReplicaConfiguration node(String hostName, int port) {
|
||||
|
||||
addNode(hostName, port);
|
||||
return this;
|
||||
@@ -151,7 +152,7 @@ public class RedisStaticMasterSlaveConfiguration implements RedisConfiguration,
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisConfiguration.StaticMasterSlaveConfiguration#getNodes()
|
||||
* @see org.springframework.data.redis.connection.RedisConfiguration.StaticMasterReplicaConfiguration#getNodes()
|
||||
*/
|
||||
@Override
|
||||
public List<RedisStandaloneConfiguration> getNodes() {
|
||||
@@ -39,7 +39,7 @@ import org.springframework.util.Assert;
|
||||
* <li>Optional {@link ClientResources}</li>
|
||||
* <li>Optional {@link ClientOptions}</li>
|
||||
* <li>Optional client name</li>
|
||||
* <li>Optional {@link ReadFrom}. Enables Master/Slave operations if configured.</li>
|
||||
* <li>Optional {@link ReadFrom}. Enables Master/Replica operations if configured.</li>
|
||||
* <li>Client {@link Duration timeout}</li>
|
||||
* <li>Shutdown {@link Duration timeout}</li>
|
||||
* </ul>
|
||||
@@ -85,6 +85,8 @@ public interface LettuceClientConfiguration {
|
||||
Optional<String> getClientName();
|
||||
|
||||
/**
|
||||
* Note: Redis is undergoing a nomenclature change where the term replica is used synonymously to slave.
|
||||
*
|
||||
* @return the optional {@link io.lettuce.core.ReadFrom} setting.
|
||||
* @since 2.1
|
||||
*/
|
||||
@@ -200,7 +202,8 @@ public interface LettuceClientConfiguration {
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure {@link ReadFrom}. Enables Master/Slave operations if configured.
|
||||
* Configure {@link ReadFrom}. Enables Master/Replica operations if configured. <br/>
|
||||
* Note: Redis is undergoing a nomenclature change where the term replica is used synonymously to slave.
|
||||
*
|
||||
* @param readFrom must not be {@literal null}.
|
||||
* @return {@literal this} builder.
|
||||
|
||||
@@ -73,7 +73,7 @@ import org.springframework.util.ClassUtils;
|
||||
* {@link LettuceConnectionFactory client configuration}. Lettuce supports the following environmental configurations:
|
||||
* <ul>
|
||||
* <li>{@link RedisStandaloneConfiguration}</li>
|
||||
* <li>{@link RedisStaticMasterSlaveConfiguration}</li>
|
||||
* <li>{@link RedisStaticMasterReplicaConfiguration}</li>
|
||||
* <li>{@link RedisSocketConfiguration}</li>
|
||||
* <li>{@link RedisSentinelConfiguration}</li>
|
||||
* <li>{@link RedisClusterConfiguration}</li>
|
||||
@@ -212,7 +212,7 @@ public class LettuceConnectionFactory
|
||||
|
||||
/**
|
||||
* Constructs a new {@link LettuceConnectionFactory} instance using the given
|
||||
* {@link RedisStaticMasterSlaveConfiguration} and {@link LettuceClientConfiguration}.
|
||||
* {@link RedisStaticMasterReplicaConfiguration} and {@link LettuceClientConfiguration}.
|
||||
*
|
||||
* @param redisConfiguration must not be {@literal null}.
|
||||
* @param clientConfig must not be {@literal null}.
|
||||
@@ -825,11 +825,11 @@ public class LettuceConnectionFactory
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true when {@link RedisStaticMasterSlaveConfiguration} is present.
|
||||
* @return true when {@link RedisStaticMasterReplicaConfiguration} is present.
|
||||
* @since 2.1
|
||||
*/
|
||||
private boolean isStaticMasterSlaveAware() {
|
||||
return RedisConfiguration.isStaticMasterSlaveConfiguration(configuration);
|
||||
private boolean isStaticMasterReplicaAware() {
|
||||
return RedisConfiguration.isStaticMasterReplicaConfiguration(configuration);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -903,14 +903,14 @@ public class LettuceConnectionFactory
|
||||
|
||||
ReadFrom readFrom = getClientConfiguration().getReadFrom().orElse(null);
|
||||
|
||||
if (isStaticMasterSlaveAware()) {
|
||||
if (isStaticMasterReplicaAware()) {
|
||||
|
||||
List<RedisURI> nodes = ((RedisStaticMasterSlaveConfiguration) configuration).getNodes().stream() //
|
||||
List<RedisURI> nodes = ((RedisStaticMasterReplicaConfiguration) configuration).getNodes().stream() //
|
||||
.map(it -> createRedisURIAndApplySettings(it.getHostName(), it.getPort())) //
|
||||
.peek(it -> it.setDatabase(getDatabase())) //
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return new StaticMasterSlaveConnectionProvider((RedisClient) client, codec, nodes, readFrom);
|
||||
return new StaticMasterReplicaConnectionProvider((RedisClient) client, codec, nodes, readFrom);
|
||||
}
|
||||
|
||||
if (isClusterAware()) {
|
||||
@@ -922,7 +922,7 @@ public class LettuceConnectionFactory
|
||||
|
||||
protected AbstractRedisClient createClient() {
|
||||
|
||||
if (isStaticMasterSlaveAware()) {
|
||||
if (isStaticMasterReplicaAware()) {
|
||||
|
||||
RedisClient redisClient = clientConfiguration.getClientResources() //
|
||||
.map(RedisClient::create) //
|
||||
|
||||
@@ -109,7 +109,7 @@ class StandaloneConnectionProvider implements LettuceConnectionProvider, TargetA
|
||||
|
||||
if (StatefulConnection.class.isAssignableFrom(connectionType)) {
|
||||
|
||||
return connectionType.cast(readFrom.map(it -> this.masterSlaveConnection(redisURISupplier.get(), it))
|
||||
return connectionType.cast(readFrom.map(it -> this.masterReplicaConnection(redisURISupplier.get(), it))
|
||||
.orElseGet(() -> client.connect(codec)));
|
||||
}
|
||||
|
||||
@@ -135,14 +135,15 @@ class StandaloneConnectionProvider implements LettuceConnectionProvider, TargetA
|
||||
if (StatefulConnection.class.isAssignableFrom(connectionType)) {
|
||||
|
||||
return connectionType
|
||||
.cast(readFrom.map(it -> this.masterSlaveConnection(redisURI, it)).orElseGet(() -> client.connect(codec)));
|
||||
.cast(readFrom.map(it -> this.masterReplicaConnection(redisURI, it)).orElseGet(() -> client.connect(codec)));
|
||||
}
|
||||
|
||||
throw new UnsupportedOperationException("Connection type " + connectionType + " not supported!");
|
||||
}
|
||||
|
||||
private StatefulRedisConnection masterSlaveConnection(RedisURI redisUri, ReadFrom readFrom) {
|
||||
private StatefulRedisConnection masterReplicaConnection(RedisURI redisUri, ReadFrom readFrom) {
|
||||
|
||||
// See https://github.com/lettuce-io/lettuce-core/issues/845 for MasterSlave -> MasterReplica change.
|
||||
StatefulRedisMasterSlaveConnection<?, ?> connection = MasterSlave.connect(client, codec, redisUri);
|
||||
connection.setReadFrom(readFrom);
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ import java.util.Optional;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* {@link LettuceConnectionProvider} implementation for a static Master/Slave connection suitable for eg. AWS
|
||||
* {@link LettuceConnectionProvider} implementation for a static Master/Replica connection suitable for eg. AWS
|
||||
* ElastiCache with replicas setup.<br/>
|
||||
* Lettuce auto-discovers node roles from the static {@link RedisURI} collection.
|
||||
*
|
||||
@@ -37,7 +37,7 @@ import org.springframework.lang.Nullable;
|
||||
* @author Christoph Strobl
|
||||
* @since 2.1
|
||||
*/
|
||||
class StaticMasterSlaveConnectionProvider implements LettuceConnectionProvider {
|
||||
class StaticMasterReplicaConnectionProvider implements LettuceConnectionProvider {
|
||||
|
||||
private final RedisClient client;
|
||||
private final RedisCodec<?, ?> codec;
|
||||
@@ -45,14 +45,14 @@ class StaticMasterSlaveConnectionProvider implements LettuceConnectionProvider {
|
||||
private final Collection<RedisURI> nodes;
|
||||
|
||||
/**
|
||||
* Create new {@link StaticMasterSlaveConnectionProvider}.
|
||||
* Create new {@link StaticMasterReplicaConnectionProvider}.
|
||||
*
|
||||
* @param client must not be {@literal null}.
|
||||
* @param codec must not be {@literal null}.
|
||||
* @param nodes must not be {@literal null}.
|
||||
* @param readFrom can be {@literal null}.
|
||||
*/
|
||||
StaticMasterSlaveConnectionProvider(RedisClient client, RedisCodec<?, ?> codec, Collection<RedisURI> nodes,
|
||||
StaticMasterReplicaConnectionProvider(RedisClient client, RedisCodec<?, ?> codec, Collection<RedisURI> nodes,
|
||||
@Nullable ReadFrom readFrom) {
|
||||
|
||||
this.client = client;
|
||||
@@ -70,6 +70,7 @@ class StaticMasterSlaveConnectionProvider implements LettuceConnectionProvider {
|
||||
|
||||
if (StatefulConnection.class.isAssignableFrom(connectionType)) {
|
||||
|
||||
// See https://github.com/lettuce-io/lettuce-core/issues/845 for MasterSlave -> MasterReplica change.
|
||||
StatefulRedisMasterSlaveConnection<?, ?> connection = MasterSlave.connect(client, codec, nodes);
|
||||
readFrom.ifPresent(connection::setReadFrom);
|
||||
|
||||
Reference in New Issue
Block a user