Search in sources :

Example 6 with RedisSentinelConfiguration

use of org.springframework.data.redis.connection.RedisSentinelConfiguration in project incubator-shenyu by apache.

the class RateLimiterPluginDataHandlerTest method redisSentinelConfigurationPropertyTest.

/**
 * redisSentinelConfiguration property test case.
 */
@Test
public void redisSentinelConfigurationPropertyTest() {
    RedisSentinelConfiguration configuration = ReflectionTestUtils.invokeMethod(rateLimiterPluginDataHandler, "redisSentinelConfiguration", generateRateLimiterConfig("localhost:2181;localhost:2182"));
    assertNotNull(configuration);
    assertEquals(DATABASE_TEST_VALUE, configuration.getDatabase());
    assertEquals(RedisPassword.of(PASSWORD_TEST_VALUE), configuration.getPassword());
    assertEquals(Collections.unmodifiableSet(Sets.newHashSet(generateRedisNode(PORT_TEST_VALUE_1), generateRedisNode(PORT_TEST_VALUE_2))), configuration.getSentinels());
}
Also used : RedisSentinelConfiguration(org.springframework.data.redis.connection.RedisSentinelConfiguration) Test(org.junit.jupiter.api.Test)

Example 7 with RedisSentinelConfiguration

use of org.springframework.data.redis.connection.RedisSentinelConfiguration in project cas by apereo.

the class RedisObjectFactory method getSentinelConfig.

private static RedisSentinelConfiguration getSentinelConfig(final BaseRedisProperties redis) {
    LOGGER.debug("Setting Redis with Sentinel configuration on master [{}]", redis.getSentinel().getMaster());
    val sentinelConfig = new RedisSentinelConfiguration().master(redis.getSentinel().getMaster());
    LOGGER.debug("Sentinel nodes configured are [{}]", redis.getSentinel().getNode());
    sentinelConfig.setSentinels(createRedisNodesForProperties(redis));
    sentinelConfig.setDatabase(redis.getDatabase());
    if (StringUtils.hasText(redis.getPassword())) {
        sentinelConfig.setPassword(RedisPassword.of(redis.getPassword()));
    }
    return sentinelConfig;
}
Also used : lombok.val(lombok.val) RedisSentinelConfiguration(org.springframework.data.redis.connection.RedisSentinelConfiguration)

Example 8 with RedisSentinelConfiguration

use of org.springframework.data.redis.connection.RedisSentinelConfiguration in project nifi by apache.

the class RedisUtils method createConnectionFactory.

public static JedisConnectionFactory createConnectionFactory(final PropertyContext context, final ComponentLog logger) {
    final String redisMode = context.getProperty(RedisUtils.REDIS_MODE).getValue();
    final String connectionString = context.getProperty(RedisUtils.CONNECTION_STRING).evaluateAttributeExpressions().getValue();
    final Integer dbIndex = context.getProperty(RedisUtils.DATABASE).evaluateAttributeExpressions().asInteger();
    final String password = context.getProperty(RedisUtils.PASSWORD).evaluateAttributeExpressions().getValue();
    final Integer timeout = context.getProperty(RedisUtils.COMMUNICATION_TIMEOUT).asTimePeriod(TimeUnit.MILLISECONDS).intValue();
    final JedisPoolConfig poolConfig = createJedisPoolConfig(context);
    JedisConnectionFactory connectionFactory;
    if (RedisUtils.REDIS_MODE_STANDALONE.getValue().equals(redisMode)) {
        final JedisShardInfo jedisShardInfo = createJedisShardInfo(connectionString, timeout, password);
        logger.info("Connecting to Redis in standalone mode at " + connectionString);
        connectionFactory = new JedisConnectionFactory(jedisShardInfo);
    } else if (RedisUtils.REDIS_MODE_SENTINEL.getValue().equals(redisMode)) {
        final String[] sentinels = connectionString.split("[,]");
        final String sentinelMaster = context.getProperty(RedisUtils.SENTINEL_MASTER).evaluateAttributeExpressions().getValue();
        final RedisSentinelConfiguration sentinelConfiguration = new RedisSentinelConfiguration(sentinelMaster, new HashSet<>(getTrimmedValues(sentinels)));
        final JedisShardInfo jedisShardInfo = createJedisShardInfo(sentinels[0], timeout, password);
        logger.info("Connecting to Redis in sentinel mode...");
        logger.info("Redis master = " + sentinelMaster);
        for (final String sentinel : sentinels) {
            logger.info("Redis sentinel at " + sentinel);
        }
        connectionFactory = new JedisConnectionFactory(sentinelConfiguration, poolConfig);
        connectionFactory.setShardInfo(jedisShardInfo);
    } else {
        final String[] clusterNodes = connectionString.split("[,]");
        final Integer maxRedirects = context.getProperty(RedisUtils.CLUSTER_MAX_REDIRECTS).asInteger();
        final RedisClusterConfiguration clusterConfiguration = new RedisClusterConfiguration(getTrimmedValues(clusterNodes));
        clusterConfiguration.setMaxRedirects(maxRedirects);
        logger.info("Connecting to Redis in clustered mode...");
        for (final String clusterNode : clusterNodes) {
            logger.info("Redis cluster node at " + clusterNode);
        }
        connectionFactory = new JedisConnectionFactory(clusterConfiguration, poolConfig);
    }
    connectionFactory.setUsePool(true);
    connectionFactory.setPoolConfig(poolConfig);
    connectionFactory.setDatabase(dbIndex);
    connectionFactory.setTimeout(timeout);
    if (!StringUtils.isBlank(password)) {
        connectionFactory.setPassword(password);
    }
    // need to call this to initialize the pool/connections
    connectionFactory.afterPropertiesSet();
    return connectionFactory;
}
Also used : RedisSentinelConfiguration(org.springframework.data.redis.connection.RedisSentinelConfiguration) JedisConnectionFactory(org.springframework.data.redis.connection.jedis.JedisConnectionFactory) JedisShardInfo(redis.clients.jedis.JedisShardInfo) RedisClusterConfiguration(org.springframework.data.redis.connection.RedisClusterConfiguration) JedisPoolConfig(redis.clients.jedis.JedisPoolConfig) HashSet(java.util.HashSet)

Example 9 with RedisSentinelConfiguration

use of org.springframework.data.redis.connection.RedisSentinelConfiguration in project incubator-shenyu by apache.

the class RateLimiterPluginDataHandler method redisSentinelConfiguration.

private RedisSentinelConfiguration redisSentinelConfiguration(final RateLimiterConfig rateLimiterConfig) {
    RedisSentinelConfiguration config = new RedisSentinelConfiguration();
    config.master(rateLimiterConfig.getMaster());
    config.setSentinels(createRedisNode(rateLimiterConfig.getUrl()));
    if (rateLimiterConfig.getPassword() != null) {
        config.setPassword(RedisPassword.of(rateLimiterConfig.getPassword()));
    }
    config.setDatabase(rateLimiterConfig.getDatabase());
    return config;
}
Also used : RedisSentinelConfiguration(org.springframework.data.redis.connection.RedisSentinelConfiguration)

Example 10 with RedisSentinelConfiguration

use of org.springframework.data.redis.connection.RedisSentinelConfiguration in project jag-file-submission by bcgov.

the class CacheConfiguration method jedisConnectionFactory.

/**
 * Configure the JedisConnectionFactory
 * @param properties The redis properties
 * @return a JedisConnectionFactory
 */
@Bean
public JedisConnectionFactory jedisConnectionFactory(RedisProperties properties) {
    if (properties.getCluster() != null) {
        RedisClusterConfiguration redisClusterConfiguration = new RedisClusterConfiguration(properties.getCluster().getNodes());
        redisClusterConfiguration.setPassword(properties.getPassword());
        if (properties.getCluster().getMaxRedirects() != null)
            redisClusterConfiguration.setMaxRedirects(properties.getCluster().getMaxRedirects());
        return new JedisConnectionFactory(redisClusterConfiguration);
    }
    if (properties.getSentinel() != null) {
        RedisSentinelConfiguration redisSantinelConfiguration = new RedisSentinelConfiguration();
        redisSantinelConfiguration.setMaster(properties.getSentinel().getMaster());
        redisSantinelConfiguration.setSentinels(createSentinels(properties.getSentinel()));
        redisSantinelConfiguration.setPassword(properties.getPassword());
        return new JedisConnectionFactory(redisSantinelConfiguration);
    }
    RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration();
    redisStandaloneConfiguration.setHostName(properties.getHost());
    redisStandaloneConfiguration.setPort(properties.getPort());
    redisStandaloneConfiguration.setPassword(properties.getPassword());
    return new JedisConnectionFactory(redisStandaloneConfiguration);
}
Also used : RedisSentinelConfiguration(org.springframework.data.redis.connection.RedisSentinelConfiguration) JedisConnectionFactory(org.springframework.data.redis.connection.jedis.JedisConnectionFactory) RedisClusterConfiguration(org.springframework.data.redis.connection.RedisClusterConfiguration) RedisStandaloneConfiguration(org.springframework.data.redis.connection.RedisStandaloneConfiguration) Bean(org.springframework.context.annotation.Bean)

Aggregations

RedisSentinelConfiguration (org.springframework.data.redis.connection.RedisSentinelConfiguration)10 RedisClusterConfiguration (org.springframework.data.redis.connection.RedisClusterConfiguration)4 RedisStandaloneConfiguration (org.springframework.data.redis.connection.RedisStandaloneConfiguration)4 LettuceConnectionFactory (org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory)3 RedisNode (org.springframework.data.redis.connection.RedisNode)2 JedisConnectionFactory (org.springframework.data.redis.connection.jedis.JedisConnectionFactory)2 RedisServerMatchStrategy (com.pamirs.attach.plugin.common.datasource.redisserver.RedisServerMatchStrategy)1 Attachment (com.pamirs.attach.plugin.dynamic.Attachment)1 RedisTemplate (com.pamirs.attach.plugin.dynamic.template.RedisTemplate)1 ShadowRedisConfig (com.pamirs.pradar.internal.config.ShadowRedisConfig)1 AbstractRedisClient (io.lettuce.core.AbstractRedisClient)1 HostAndPort (io.lettuce.core.internal.HostAndPort)1 ChannelGroup (io.netty.channel.group.ChannelGroup)1 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)1 InetSocketAddress (java.net.InetSocketAddress)1 HashSet (java.util.HashSet)1 lombok.val (lombok.val)1 Test (org.junit.jupiter.api.Test)1 Bean (org.springframework.context.annotation.Bean)1 JedisPoolConfig (redis.clients.jedis.JedisPoolConfig)1