Search in sources :

Example 1 with LettuceClientConfigurationBuilder

use of org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration.LettuceClientConfigurationBuilder in project spring-boot by spring-projects.

the class LettuceConnectionConfiguration method getLettuceClientConfiguration.

private LettuceClientConfiguration getLettuceClientConfiguration(ObjectProvider<LettuceClientConfigurationBuilderCustomizer> builderCustomizers, ClientResources clientResources, Pool pool) {
    LettuceClientConfigurationBuilder builder = createBuilder(pool);
    applyProperties(builder);
    if (StringUtils.hasText(getProperties().getUrl())) {
        customizeConfigurationFromUrl(builder);
    }
    builder.clientOptions(createClientOptions());
    builder.clientResources(clientResources);
    builderCustomizers.orderedStream().forEach((customizer) -> customizer.customize(builder));
    return builder.build();
}
Also used : LettuceClientConfigurationBuilder(org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration.LettuceClientConfigurationBuilder)

Example 2 with LettuceClientConfigurationBuilder

use of org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration.LettuceClientConfigurationBuilder in project dhis2-core by dhis2.

the class RedisConfiguration method lettuceConnectionFactory.

@Bean
public LettuceConnectionFactory lettuceConnectionFactory() {
    LettuceClientConfigurationBuilder builder = LettuceClientConfiguration.builder();
    if (DhisConfigurationProvider.isOn((String) redisSslEnabled().getObject())) {
        builder.useSsl();
    }
    LettuceClientConfiguration clientConfiguration = builder.build();
    RedisStandaloneConfiguration standaloneConfig = new RedisStandaloneConfiguration();
    standaloneConfig.setHostName((String) redisHost().getObject());
    standaloneConfig.setPassword((String) redisPassword().getObject());
    standaloneConfig.setPort(Integer.parseInt((String) redisPort().getObject()));
    return new LettuceConnectionFactory(standaloneConfig, clientConfiguration);
}
Also used : LettuceClientConfiguration(org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration) LettuceConnectionFactory(org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory) RedisStandaloneConfiguration(org.springframework.data.redis.connection.RedisStandaloneConfiguration) LettuceClientConfigurationBuilder(org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration.LettuceClientConfigurationBuilder) ConfigurationPropertyFactoryBean(org.hisp.dhis.external.conf.ConfigurationPropertyFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 3 with LettuceClientConfigurationBuilder

use of org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration.LettuceClientConfigurationBuilder 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

LettuceClientConfigurationBuilder (org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration.LettuceClientConfigurationBuilder)3 RedisStandaloneConfiguration (org.springframework.data.redis.connection.RedisStandaloneConfiguration)2 LettuceConnectionFactory (org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory)2 ConfigurationPropertyFactoryBean (org.hisp.dhis.external.conf.ConfigurationPropertyFactoryBean)1 PooledServiceConnectorConfig (org.springframework.cloud.service.PooledServiceConnectorConfig)1 ServiceConnectorCreationException (org.springframework.cloud.service.ServiceConnectorCreationException)1 Bean (org.springframework.context.annotation.Bean)1 JedisClientConfigurationBuilder (org.springframework.data.redis.connection.jedis.JedisClientConfiguration.JedisClientConfigurationBuilder)1 JedisConnectionFactory (org.springframework.data.redis.connection.jedis.JedisConnectionFactory)1 LettuceClientConfiguration (org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration)1