Search in sources :

Example 11 with RedisNodeDescription

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

the class ReadFromUnitTests method subnetIpv6RuleAnyNode.

@Test
void subnetIpv6RuleAnyNode() {
    ReadFrom sut = ReadFrom.subnet("::/0");
    RedisClusterNode node = createNodeWithHost("2001:db8:abcd:1000::");
    List<RedisNodeDescription> result = sut.select(getNodes(node));
    assertThat(result).hasSize(1).containsExactly(node);
}
Also used : RedisClusterNode(io.lettuce.core.cluster.models.partitions.RedisClusterNode) RedisNodeDescription(io.lettuce.core.models.role.RedisNodeDescription) ReadFrom(io.lettuce.core.ReadFrom) Test(org.junit.jupiter.api.Test)

Example 12 with RedisNodeDescription

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

the class ReadFromUnitTests method subnetIpv4RuleAnyNode.

@Test
void subnetIpv4RuleAnyNode() {
    ReadFrom sut = ReadFrom.subnet("0.0.0.0/0");
    RedisClusterNode node = createNodeWithHost("192.0.2.1");
    List<RedisNodeDescription> result = sut.select(getNodes(node));
    assertThat(result).hasSize(1).containsExactly(node);
}
Also used : RedisClusterNode(io.lettuce.core.cluster.models.partitions.RedisClusterNode) RedisNodeDescription(io.lettuce.core.models.role.RedisNodeDescription) ReadFrom(io.lettuce.core.ReadFrom) Test(org.junit.jupiter.api.Test)

Example 13 with RedisNodeDescription

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

the class ReadFromUnitTests method subnetIpv4Ipv6Mixed.

@Test
void subnetIpv4Ipv6Mixed() {
    ReadFrom sut = ReadFrom.subnet("192.0.2.0/24", "2001:db8:abcd:0000::/52");
    RedisClusterNode nodeInSubnetIpv4 = createNodeWithHost("192.0.2.1");
    RedisClusterNode nodeNotInSubnetIpv4 = createNodeWithHost("198.51.100.1");
    RedisClusterNode nodeInSubnetIpv6 = createNodeWithHost("2001:db8:abcd:0000::1");
    RedisClusterNode nodeNotInSubnetIpv6 = createNodeWithHost("2001:db8:abcd:1000::");
    List<RedisNodeDescription> result = sut.select(getNodes(nodeInSubnetIpv4, nodeNotInSubnetIpv4, nodeInSubnetIpv6, nodeNotInSubnetIpv6));
    assertThat(result).hasSize(2).containsExactly(nodeInSubnetIpv4, nodeInSubnetIpv6);
}
Also used : RedisClusterNode(io.lettuce.core.cluster.models.partitions.RedisClusterNode) RedisNodeDescription(io.lettuce.core.models.role.RedisNodeDescription) ReadFrom(io.lettuce.core.ReadFrom) Test(org.junit.jupiter.api.Test)

Example 14 with RedisNodeDescription

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

the class ReadFromUnitTests method regex.

@Test
void regex() {
    ReadFrom sut = ReadFrom.regex(Pattern.compile(".*region-1.*"));
    RedisClusterNode node1 = createNodeWithHost("redis-node-1.region-1.example.com");
    RedisClusterNode node2 = createNodeWithHost("redis-node-2.region-1.example.com");
    RedisClusterNode node3 = createNodeWithHost("redis-node-1.region-2.example.com");
    RedisClusterNode node4 = createNodeWithHost("redis-node-2.region-2.example.com");
    List<RedisNodeDescription> result = sut.select(getNodes(node1, node2, node3, node4));
    assertThat(result).hasSize(2).containsExactly(node1, node2);
}
Also used : RedisClusterNode(io.lettuce.core.cluster.models.partitions.RedisClusterNode) RedisNodeDescription(io.lettuce.core.models.role.RedisNodeDescription) ReadFrom(io.lettuce.core.ReadFrom) Test(org.junit.jupiter.api.Test)

Example 15 with RedisNodeDescription

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

the class ReplicaTopologyProvider method getReplicasFromInfo.

private List<RedisNodeDescription> getReplicasFromInfo(String info) {
    List<RedisNodeDescription> replicas = new ArrayList<>();
    Matcher matcher = SLAVE_PATTERN.matcher(info);
    while (matcher.find()) {
        String group = matcher.group(2);
        String ip = getNested(IP_PATTERN, group, 1);
        String port = getNested(PORT_PATTERN, group, 1);
        replicas.add(new RedisMasterReplicaNode(ip, Integer.parseInt(port), redisURI, RedisInstance.Role.SLAVE));
    }
    return replicas;
}
Also used : Matcher(java.util.regex.Matcher) RedisNodeDescription(io.lettuce.core.models.role.RedisNodeDescription) ArrayList(java.util.ArrayList)

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