Search in sources :

Example 1 with RedisNodeDescription

use of io.lettuce.core.models.role.RedisNodeDescription in project LinkAgent by shulieTech.

the class MasterSlaveTopologyRefreshGetconnectionInteceptor method doBefore.

@Override
public void doBefore(Advice advice) throws Throwable {
    try {
        Iterable<RedisNodeDescription> iterable = (Iterable) advice.getParameterArray()[0];
        Iterator iterator = iterable.iterator();
        while (iterator.hasNext()) {
            RedisNodeDescription next = (RedisNodeDescription) iterator.next();
            RedisURI uri = next.getUri();
            LettuceUtils.cachePressureNode(uri);
        }
    } catch (Throwable t) {
        logger.error(Throwables.getStackTraceAsString(t));
    }
}
Also used : RedisURI(io.lettuce.core.RedisURI) RedisNodeDescription(io.lettuce.core.models.role.RedisNodeDescription) Iterator(java.util.Iterator)

Example 2 with RedisNodeDescription

use of io.lettuce.core.models.role.RedisNodeDescription in project lettuce-core by lettuce-io.

the class MasterReplicaTopologyProviderUnitTests method shouldParseMaster.

@Test
void shouldParseMaster() {
    String info = "# Replication\r\n" + "role:master\r\n" + "connected_slaves:1\r\n" + "master_repl_offset:56276\r\n" + "repl_backlog_active:1\r\n";
    List<RedisNodeDescription> result = sut.getNodesFromInfo(info);
    assertThat(result).hasSize(1);
    RedisNodeDescription redisNodeDescription = result.get(0);
    assertThat(redisNodeDescription.getRole().isUpstream()).isTrue();
    assertThat(redisNodeDescription.getUri().getHost()).isEqualTo(TestSettings.host());
    assertThat(redisNodeDescription.getUri().getPort()).isEqualTo(TestSettings.port());
}
Also used : RedisNodeDescription(io.lettuce.core.models.role.RedisNodeDescription) Test(org.junit.jupiter.api.Test)

Example 3 with RedisNodeDescription

use of io.lettuce.core.models.role.RedisNodeDescription in project lettuce-core by lettuce-io.

the class MasterReplicaTopologyProviderUnitTests method shouldParseMasterAndReplica.

@Test
void shouldParseMasterAndReplica() {
    String info = "# Replication\r\n" + "role:slave\r\n" + "connected_slaves:1\r\n" + "master_host:127.0.0.1\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("127.0.0.1");
}
Also used : RedisNodeDescription(io.lettuce.core.models.role.RedisNodeDescription) Test(org.junit.jupiter.api.Test)

Example 4 with RedisNodeDescription

use of io.lettuce.core.models.role.RedisNodeDescription in project lettuce-core by lettuce-io.

the class MasterReplicaTopologyProviderUnitTests method shouldParseReplicas.

@Test
void shouldParseReplicas() {
    String info = "# Replication\r\n" + "role:master\r\n" + "slave0:ip=127.0.0.1,port=6483,state=online,offset=56276,lag=0\r\n" + "slave1:ip=127.0.0.1,port=6484,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(3);
    RedisNodeDescription replica1 = result.get(1);
    assertThat(replica1.getRole()).isEqualTo(RedisInstance.Role.SLAVE);
    assertThat(replica1.getUri().getHost()).isEqualTo("127.0.0.1");
    assertThat(replica1.getUri().getPort()).isEqualTo(6483);
    RedisNodeDescription replica2 = result.get(2);
    assertThat(replica2.getRole()).isEqualTo(RedisInstance.Role.SLAVE);
    assertThat(replica2.getUri().getHost()).isEqualTo("127.0.0.1");
    assertThat(replica2.getUri().getPort()).isEqualTo(6484);
}
Also used : RedisNodeDescription(io.lettuce.core.models.role.RedisNodeDescription) Test(org.junit.jupiter.api.Test)

Example 5 with RedisNodeDescription

use of io.lettuce.core.models.role.RedisNodeDescription in project lettuce-core by lettuce-io.

the class MasterReplicaTopologyProviderUnitTests method shouldParseIPv6UpstreamAddress.

@Test
void shouldParseIPv6UpstreamAddress() {
    String info = "# Replication\r\n" + "role:slave\r\n" + "connected_slaves:1\r\n" + "master_host:::20f8:1400:0:0\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("::20f8:1400:0:0");
}
Also used : RedisNodeDescription(io.lettuce.core.models.role.RedisNodeDescription) Test(org.junit.jupiter.api.Test)

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