use of io.lettuce.core.models.role.RedisNodeDescription in project lettuce-core by lettuce-io.
the class MasterReplicaTopologyProviderUnitTests method shouldParseIPv6SlaveAddress.
@Test
void shouldParseIPv6SlaveAddress() {
String info = "# Replication\r\n" + "role:master\r\n" + "slave0:ip=::20f8:1400:0:0,port=6483,state=online,offset=56276,lag=0\r\n" + "master_repl_offset:56276\r\n" + "repl_backlog_active:1\r\n";
List<RedisNodeDescription> result = sut.getNodesFromInfo(info);
assertThat(result).hasSize(2);
RedisNodeDescription replica1 = result.get(1);
assertThat(replica1.getRole()).isEqualTo(RedisInstance.Role.SLAVE);
assertThat(replica1.getUri().getHost()).isEqualTo("::20f8:1400:0:0");
assertThat(replica1.getUri().getPort()).isEqualTo(6483);
}
use of io.lettuce.core.models.role.RedisNodeDescription in project lettuce-core by lettuce-io.
the class MasterReplicaTopologyProviderUnitTests method shouldParseMasterHostname.
@Test
void shouldParseMasterHostname() {
String info = "# Replication\r\n" + "role:slave\r\n" + "connected_slaves:1\r\n" + "master_host:my.Host-name.COM\r\n" + "master_port:1234\r\n" + "master_repl_offset:56276\r\n" + "repl_backlog_active:1\r\n";
List<RedisNodeDescription> result = sut.getNodesFromInfo(info);
assertThat(result).hasSize(2);
RedisNodeDescription replica = result.get(0);
assertThat(replica.getRole().isReplica()).isTrue();
RedisNodeDescription upstream = result.get(1);
assertThat(upstream.getRole().isUpstream()).isTrue();
assertThat(upstream.getUri().getHost()).isEqualTo("my.Host-name.COM");
}
use of io.lettuce.core.models.role.RedisNodeDescription in project lettuce-core by lettuce-io.
the class MasterReplicaTopologyRefreshUnitTests method shouldRetrieveTopologyWithFailedNode.
@Test
void shouldRetrieveTopologyWithFailedNode() {
MasterReplicaTopologyRefresh refresh = new MasterReplicaTopologyRefresh(connectionFactory, executorService, provider);
CompletableFuture<StatefulRedisConnection<String, String>> connected = CompletableFuture.completedFuture(connection);
CompletableFuture<StatefulRedisConnection<String, String>> pending = new CompletableFuture<>();
when(connectionFactory.connectToNodeAsync(any(), any())).thenReturn((CompletableFuture) connected, (CompletableFuture) pending);
RedisURI redisURI = new RedisURI();
redisURI.setTimeout(Duration.ofMillis(1));
List<RedisNodeDescription> nodes = refresh.getNodes(redisURI).block();
assertThat(nodes).hasSize(1).containsOnly(UPSTREAM);
}
use of io.lettuce.core.models.role.RedisNodeDescription in project lettuce-core by lettuce-io.
the class AutodiscoveryConnector method getMasterConnectionAndUri.
private Mono<Tuple2<RedisURI, StatefulRedisConnection<K, V>>> getMasterConnectionAndUri(List<RedisNodeDescription> nodes, Tuple2<RedisURI, StatefulRedisConnection<K, V>> connectionTuple, RedisCodec<K, V> codec) {
RedisNodeDescription node = getConnectedNode(redisURI, nodes);
if (!node.getRole().isUpstream()) {
RedisNodeDescription master = lookupMaster(nodes);
ConnectionFuture<StatefulRedisConnection<K, V>> masterConnection = redisClient.connectAsync(codec, master.getUri());
return //
Mono.just(master.getUri()).zipWith(Mono.fromCompletionStage(masterConnection)).doOnNext(it -> {
initialConnections.put(it.getT1(), it.getT2());
});
}
return Mono.just(connectionTuple);
}
use of io.lettuce.core.models.role.RedisNodeDescription in project lettuce-core by lettuce-io.
the class PooledClusterConnectionProvider method getReadFromConnections.
private CompletableFuture<StatefulRedisConnection<K, V>>[] getReadFromConnections(List<RedisNodeDescription> selection) {
// Use always host and port for slot-oriented operations. We don't want to get reconnected on a different
// host because the nodeId can be handled by a different host.
CompletableFuture<StatefulRedisConnection<K, V>>[] readerCandidates = new CompletableFuture[selection.size()];
for (int i = 0; i < selection.size(); i++) {
RedisNodeDescription redisClusterNode = selection.get(i);
RedisURI uri = redisClusterNode.getUri();
ConnectionKey key = new ConnectionKey(redisClusterNode.getRole().isUpstream() ? Intent.WRITE : Intent.READ, uri.getHost(), uri.getPort());
readerCandidates[i] = getConnectionAsync(key).toCompletableFuture();
}
return readerCandidates;
}
Aggregations