Search in sources :

Example 6 with RedisNodeDescription

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);
}
Also used : RedisNodeDescription(io.lettuce.core.models.role.RedisNodeDescription) Test(org.junit.jupiter.api.Test)

Example 7 with RedisNodeDescription

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");
}
Also used : RedisNodeDescription(io.lettuce.core.models.role.RedisNodeDescription) Test(org.junit.jupiter.api.Test)

Example 8 with RedisNodeDescription

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);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) RedisURI(io.lettuce.core.RedisURI) RedisNodeDescription(io.lettuce.core.models.role.RedisNodeDescription) StatefulRedisConnection(io.lettuce.core.api.StatefulRedisConnection) Test(org.junit.jupiter.api.Test)

Example 9 with RedisNodeDescription

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);
}
Also used : RedisNodeDescription(io.lettuce.core.models.role.RedisNodeDescription) StatefulRedisConnection(io.lettuce.core.api.StatefulRedisConnection)

Example 10 with RedisNodeDescription

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;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) RedisURI(io.lettuce.core.RedisURI) RedisNodeDescription(io.lettuce.core.models.role.RedisNodeDescription) ConnectionKey(io.lettuce.core.cluster.ClusterNodeConnectionFactory.ConnectionKey)

Aggregations

RedisNodeDescription (io.lettuce.core.models.role.RedisNodeDescription)25 Test (org.junit.jupiter.api.Test)15 RedisClusterNode (io.lettuce.core.cluster.models.partitions.RedisClusterNode)9 ReadFrom (io.lettuce.core.ReadFrom)8 RedisURI (io.lettuce.core.RedisURI)7 StatefulRedisConnection (io.lettuce.core.api.StatefulRedisConnection)5 ArrayList (java.util.ArrayList)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 Iterator (java.util.Iterator)3 List (java.util.List)3 RedisConnectionException (io.lettuce.core.RedisConnectionException)2 ConnectionKey (io.lettuce.core.cluster.ClusterNodeConnectionFactory.ConnectionKey)2 ConnectionFuture (io.lettuce.core.ConnectionFuture)1 OrderingReadFromAccessor (io.lettuce.core.OrderingReadFromAccessor)1 RedisChannelWriter (io.lettuce.core.RedisChannelWriter)1 RedisException (io.lettuce.core.RedisException)1 RedisFuture (io.lettuce.core.RedisFuture)1 StatefulConnection (io.lettuce.core.api.StatefulConnection)1 PushMessage (io.lettuce.core.api.push.PushMessage)1 RedisClusterPushListener (io.lettuce.core.cluster.api.push.RedisClusterPushListener)1