Example usage for org.springframework.data.redis.connection RedisStaticMasterReplicaConfiguration RedisStaticMasterReplicaConfiguration

List of usage examples for org.springframework.data.redis.connection RedisStaticMasterReplicaConfiguration RedisStaticMasterReplicaConfiguration

Introduction

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

Prototype

public RedisStaticMasterReplicaConfiguration(String hostName) 

Source Link

Document

Create a new StaticMasterReplicaConfiguration given hostName .

Usage

From source file:org.springframework.data.redis.connection.lettuce.LettuceConnectionFactoryTests.java

@Test // DATAREDIS-762, DATAREDIS-869
public void factoryUsesElastiCacheMasterReplicaConnections() {

    assumeThat(String.format("No slaves connected to %s:%s.", SettingsUtils.getHost(), SettingsUtils.getPort()),
            connection.info("replication").getProperty("connected_slaves", "0").compareTo("0") > 0, is(true));

    LettuceClientConfiguration configuration = LettuceTestClientConfiguration.builder().readFrom(ReadFrom.SLAVE)
            .build();/*from  ww w  .  ja  va2  s .c om*/

    RedisStaticMasterReplicaConfiguration elastiCache = new RedisStaticMasterReplicaConfiguration(
            SettingsUtils.getHost()).node(SettingsUtils.getHost(), SettingsUtils.getPort() + 1);

    LettuceConnectionFactory factory = new LettuceConnectionFactory(elastiCache, configuration);
    factory.afterPropertiesSet();

    RedisConnection connection = factory.getConnection();

    try {
        assertThat(connection.ping(), is(equalTo("PONG")));
        assertThat(connection.info().getProperty("role"), is(equalTo("slave")));
    } finally {
        connection.close();
    }

    factory.destroy();
}