Example usage for org.springframework.data.redis.connection RedisSentinelConfiguration sentinel

List of usage examples for org.springframework.data.redis.connection RedisSentinelConfiguration sentinel

Introduction

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

Prototype

public RedisSentinelConfiguration sentinel(String host, Integer port) 

Source Link

Usage

From source file:com.hp.autonomy.frontend.find.hod.beanconfiguration.RedisConfiguration.java

@Bean
public JedisConnectionFactory redisConnectionFactory() {
    final RedisConfig config = configService.getConfig().getRedis();
    final JedisConnectionFactory connectionFactory;

    //If we haven't specified any sentinels then assume non-distributed setup
    if (config.getSentinels().isEmpty()) {
        connectionFactory = new JedisConnectionFactory();
        connectionFactory.setHostName(config.getAddress().getHost());
        connectionFactory.setPort(config.getAddress().getPort());
    } else {/*  www .j a  va  2 s.  c  om*/
        final RedisSentinelConfiguration sentinelConfig = new RedisSentinelConfiguration()
                .master(config.getMasterName());
        for (final HostAndPort node : config.getSentinels()) {
            sentinelConfig.sentinel(node.getHost(), node.getPort());
        }

        connectionFactory = new JedisConnectionFactory(sentinelConfig);
    }

    final Integer database = config.getDatabase();

    if (database != null) {
        connectionFactory.setDatabase(database);
    }

    connectionFactory.setPassword(config.getPassword());

    return connectionFactory;
}