Search in sources :

Example 1 with JedisClientConfigurationBuilder

use of org.springframework.data.redis.connection.jedis.JedisClientConfiguration.JedisClientConfigurationBuilder in project spring-boot by spring-projects.

the class JedisConnectionConfiguration method getJedisClientConfiguration.

private JedisClientConfiguration getJedisClientConfiguration(ObjectProvider<JedisClientConfigurationBuilderCustomizer> builderCustomizers) {
    JedisClientConfigurationBuilder builder = applyProperties(JedisClientConfiguration.builder());
    RedisProperties.Pool pool = getProperties().getJedis().getPool();
    if (isPoolEnabled(pool)) {
        applyPooling(pool, builder);
    }
    if (StringUtils.hasText(getProperties().getUrl())) {
        customizeConfigurationFromUrl(builder);
    }
    builderCustomizers.orderedStream().forEach((customizer) -> customizer.customize(builder));
    return builder.build();
}
Also used : JedisClientConfigurationBuilder(org.springframework.data.redis.connection.jedis.JedisClientConfiguration.JedisClientConfigurationBuilder)

Example 2 with JedisClientConfigurationBuilder

use of org.springframework.data.redis.connection.jedis.JedisClientConfiguration.JedisClientConfigurationBuilder in project spring-cloud-connectors by spring-cloud.

the class RedisConnectionFactoryCreator method create.

@Override
public RedisConnectionFactory create(RedisServiceInfo serviceInfo, ServiceConnectorConfig serviceConnectorConfig) {
    RedisStandaloneConfiguration configuration = new RedisStandaloneConfiguration();
    configuration.setHostName(serviceInfo.getHost());
    configuration.setPort(serviceInfo.getPort());
    configuration.setPassword(RedisPassword.of(serviceInfo.getPassword()));
    if (hasClass(JEDIS_CLASS_NAME)) {
        JedisClientConfigurationBuilder builder = JedisClientConfiguration.builder();
        RedisJedisClientConfigurer clientConfigurer = new RedisJedisClientConfigurer();
        if (serviceConnectorConfig instanceof RedisConnectionFactoryConfig) {
            clientConfigurer.configure(builder, (RedisConnectionFactoryConfig) serviceConnectorConfig);
        } else {
            clientConfigurer.configure(builder, (PooledServiceConnectorConfig) serviceConnectorConfig);
        }
        if (connectionIsSecure(serviceInfo)) {
            builder.useSsl();
        }
        JedisConnectionFactory connectionFactory = new JedisConnectionFactory(configuration, builder.build());
        connectionFactory.afterPropertiesSet();
        return connectionFactory;
    } else if (hasClass(LETTUCE_CLASS_NAME)) {
        LettuceClientConfigurationBuilder builder;
        if (serviceConnectorConfig != null && ((PooledServiceConnectorConfig) serviceConnectorConfig).getPoolConfig() != null) {
            if (!hasClass(APACHE_COMMONS_POOL_CLASS_NAME)) {
                throw new ServiceConnectorCreationException(String.format("Failed to create cloud Redis " + "connection factory for %s service. Apache Commons Pool must be available on " + "the classpath if pooling parameters are provided.", serviceInfo.getId()));
            }
            builder = LettucePoolingClientConfiguration.builder();
        } else {
            builder = LettuceClientConfiguration.builder();
        }
        if (connectionIsSecure(serviceInfo)) {
            builder.useSsl();
        }
        RedisLettuceClientConfigurer clientConfigurer = new RedisLettuceClientConfigurer();
        if (serviceConnectorConfig instanceof RedisConnectionFactoryConfig) {
            clientConfigurer.configure(builder, (RedisConnectionFactoryConfig) serviceConnectorConfig);
        } else {
            clientConfigurer.configure(builder, (PooledServiceConnectorConfig) serviceConnectorConfig);
        }
        LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory(configuration, builder.build());
        connectionFactory.afterPropertiesSet();
        return connectionFactory;
    } else {
        throw new ServiceConnectorCreationException(String.format("Failed to create cloud Redis " + "connection factory for %s service. No client implementation classes " + " of Jedis or Lettuce clients implementation (%s, %s) not found", serviceInfo.getId(), JEDIS_CLASS_NAME, LETTUCE_CLASS_NAME));
    }
}
Also used : JedisClientConfigurationBuilder(org.springframework.data.redis.connection.jedis.JedisClientConfiguration.JedisClientConfigurationBuilder) ServiceConnectorCreationException(org.springframework.cloud.service.ServiceConnectorCreationException) JedisConnectionFactory(org.springframework.data.redis.connection.jedis.JedisConnectionFactory) PooledServiceConnectorConfig(org.springframework.cloud.service.PooledServiceConnectorConfig) LettuceConnectionFactory(org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory) RedisStandaloneConfiguration(org.springframework.data.redis.connection.RedisStandaloneConfiguration) LettuceClientConfigurationBuilder(org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration.LettuceClientConfigurationBuilder)

Aggregations

JedisClientConfigurationBuilder (org.springframework.data.redis.connection.jedis.JedisClientConfiguration.JedisClientConfigurationBuilder)2 PooledServiceConnectorConfig (org.springframework.cloud.service.PooledServiceConnectorConfig)1 ServiceConnectorCreationException (org.springframework.cloud.service.ServiceConnectorCreationException)1 RedisStandaloneConfiguration (org.springframework.data.redis.connection.RedisStandaloneConfiguration)1 JedisConnectionFactory (org.springframework.data.redis.connection.jedis.JedisConnectionFactory)1 LettuceClientConfigurationBuilder (org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration.LettuceClientConfigurationBuilder)1 LettuceConnectionFactory (org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory)1