Example usage for org.springframework.data.redis.connection RedisClusterConfiguration getClusterNodes

List of usage examples for org.springframework.data.redis.connection RedisClusterConfiguration getClusterNodes

Introduction

In this page you can find the example usage for org.springframework.data.redis.connection RedisClusterConfiguration getClusterNodes.

Prototype

@Override
    public Set<RedisNode> getClusterNodes() 

Source Link

Usage

From source file:org.springframework.boot.autoconfigure.data.redis.RedisAutoConfigurationTests.java

@Test
public void testRedisConfigurationWithCluster() {
    List<String> clusterNodes = Arrays.asList("127.0.0.1:27379", "127.0.0.1:27380");
    this.contextRunner.withPropertyValues("spring.redis.cluster.nodes[0]:" + clusterNodes.get(0),
            "spring.redis.cluster.nodes[1]:" + clusterNodes.get(1)).run((context) -> {
                RedisClusterConfiguration clusterConfiguration = context.getBean(LettuceConnectionFactory.class)
                        .getClusterConfiguration();
                assertThat(clusterConfiguration.getClusterNodes()).hasSize(2);
                assertThat(clusterConfiguration.getClusterNodes())
                        .extracting((node) -> node.getHost() + ":" + node.getPort())
                        .containsExactlyInAnyOrder("127.0.0.1:27379", "127.0.0.1:27380");
            });//from   w  w w .  java 2s.c  o m

}

From source file:org.springframework.data.redis.connection.jedis.JedisConnectionFactory.java

/**
 * Creates {@link JedisCluster} for given {@link RedisClusterConfiguration} and {@link GenericObjectPoolConfig}.
 * /*w  w  w. j  a  v a 2  s  .com*/
 * @param clusterConfig must not be {@literal null}.
 * @param poolConfig can be {@literal null}.
 * @return
 * @since 1.7
 */
protected JedisCluster createCluster(RedisClusterConfiguration clusterConfig,
        GenericObjectPoolConfig poolConfig) {

    Assert.notNull("Cluster configuration must not be null!");

    Set<HostAndPort> hostAndPort = new HashSet<HostAndPort>();
    for (RedisNode node : clusterConfig.getClusterNodes()) {
        hostAndPort.add(new HostAndPort(node.getHost(), node.getPort()));
    }

    int redirects = clusterConfig.getMaxRedirects() != null ? clusterConfig.getMaxRedirects().intValue() : 5;

    if (StringUtils.hasText(getPassword())) {
        throw new IllegalArgumentException(
                "Jedis does not support password protected Redis Cluster configurations!");
    }

    if (poolConfig != null) {
        return new JedisCluster(hostAndPort, timeout, redirects, poolConfig);
    }
    return new JedisCluster(hostAndPort, timeout, redirects, poolConfig);
}