Search in sources :

Example 11 with LettuceConnectionFactory

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

the class RedisAutoConfigurationTests method testRedisConfigurationWithCustomPoolSettings.

@Test
void testRedisConfigurationWithCustomPoolSettings() {
    this.contextRunner.withPropertyValues("spring.redis.host:foo", "spring.redis.lettuce.pool.min-idle:1", "spring.redis.lettuce.pool.max-idle:4", "spring.redis.lettuce.pool.max-active:16", "spring.redis.lettuce.pool.max-wait:2000", "spring.redis.lettuce.pool.time-between-eviction-runs:30000", "spring.redis.lettuce.shutdown-timeout:1000").run((context) -> {
        LettuceConnectionFactory cf = context.getBean(LettuceConnectionFactory.class);
        assertThat(cf.getHostName()).isEqualTo("foo");
        GenericObjectPoolConfig<?> poolConfig = getPoolingClientConfiguration(cf).getPoolConfig();
        assertThat(poolConfig.getMinIdle()).isEqualTo(1);
        assertThat(poolConfig.getMaxIdle()).isEqualTo(4);
        assertThat(poolConfig.getMaxTotal()).isEqualTo(16);
        assertThat(poolConfig.getMaxWaitDuration()).isEqualTo(Duration.ofSeconds(2));
        assertThat(poolConfig.getDurationBetweenEvictionRuns()).isEqualTo(Duration.ofSeconds(30));
        assertThat(cf.getShutdownTimeout()).isEqualTo(1000);
    });
}
Also used : LettuceConnectionFactory(org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory) Test(org.junit.jupiter.api.Test)

Example 12 with LettuceConnectionFactory

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

the class RedisAutoConfigurationLettuceWithoutCommonsPool2Tests method poolWithoutCommonsPool2IsDisabledByDefault.

@Test
void poolWithoutCommonsPool2IsDisabledByDefault() {
    this.contextRunner.withPropertyValues("spring.redis.host:foo").run((context) -> {
        LettuceConnectionFactory cf = context.getBean(LettuceConnectionFactory.class);
        assertThat(cf.getHostName()).isEqualTo("foo");
        assertThat(cf.getClientConfiguration()).isNotInstanceOf(LettucePoolingClientConfiguration.class);
    });
}
Also used : LettuceConnectionFactory(org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory) Test(org.junit.jupiter.api.Test)

Example 13 with LettuceConnectionFactory

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

the class RedisAutoConfigurationTests method testOverrideRedisConfiguration.

@Test
void testOverrideRedisConfiguration() {
    this.contextRunner.withPropertyValues("spring.redis.host:foo", "spring.redis.database:1", "spring.redis.lettuce.shutdown-timeout:500").run((context) -> {
        LettuceConnectionFactory cf = context.getBean(LettuceConnectionFactory.class);
        assertThat(cf.getHostName()).isEqualTo("foo");
        assertThat(cf.getDatabase()).isEqualTo(1);
        assertThat(getUserName(cf)).isNull();
        assertThat(cf.getPassword()).isNull();
        assertThat(cf.isUseSsl()).isFalse();
        assertThat(cf.getShutdownTimeout()).isEqualTo(500);
    });
}
Also used : LettuceConnectionFactory(org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory) Test(org.junit.jupiter.api.Test)

Example 14 with LettuceConnectionFactory

use of org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory 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 15 with LettuceConnectionFactory

use of org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory in project spring-cloud-connectors by spring-cloud.

the class RedisConnectionFactoryCloudConfigTestHelper method assertPoolProperties.

public static void assertPoolProperties(RedisConnectionFactory connector, int maxActive, int minIdle, long maxWait) {
    GenericObjectPoolConfig poolConfig = null;
    if (connector instanceof JedisConnectionFactory) {
        poolConfig = ((JedisConnectionFactory) connector).getPoolConfig();
    } else if (connector instanceof LettuceConnectionFactory) {
        LettuceClientConfiguration config = ((LettuceConnectionFactory) connector).getClientConfiguration();
        assertThat(config, instanceOf(LettucePoolingClientConfiguration.class));
        poolConfig = ((LettucePoolingClientConfiguration) config).getPoolConfig();
    }
    assertCommonsPoolProperties(poolConfig, maxActive, minIdle, maxWait);
}
Also used : GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) JedisConnectionFactory(org.springframework.data.redis.connection.jedis.JedisConnectionFactory) LettuceClientConfiguration(org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration) LettuceConnectionFactory(org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory) LettucePoolingClientConfiguration(org.springframework.data.redis.connection.lettuce.LettucePoolingClientConfiguration)

Aggregations

LettuceConnectionFactory (org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory)27 Test (org.junit.jupiter.api.Test)16 JedisConnectionFactory (org.springframework.data.redis.connection.jedis.JedisConnectionFactory)5 Bean (org.springframework.context.annotation.Bean)4 RedisStandaloneConfiguration (org.springframework.data.redis.connection.RedisStandaloneConfiguration)3 Test (org.junit.Test)2 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)2 ServiceConnectorCreationException (org.springframework.cloud.service.ServiceConnectorCreationException)2 LettuceClientConfiguration (org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration)2 LettuceClientConfigurationBuilder (org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration.LettuceClientConfigurationBuilder)2 LoadingCacheTest (com.alicp.jetcache.LoadingCacheTest)1 RefreshCacheTest (com.alicp.jetcache.RefreshCacheTest)1 AbstractExternalCacheTest (com.alicp.jetcache.test.external.AbstractExternalCacheTest)1 GenericObjectPoolConfig (org.apache.commons.pool2.impl.GenericObjectPoolConfig)1 ConfigurationPropertyFactoryBean (org.hisp.dhis.external.conf.ConfigurationPropertyFactoryBean)1 Pool (org.springframework.boot.autoconfigure.data.redis.RedisProperties.Pool)1 Cloud (org.springframework.cloud.Cloud)1 CloudFactory (org.springframework.cloud.CloudFactory)1 PooledServiceConnectorConfig (org.springframework.cloud.service.PooledServiceConnectorConfig)1 Profile (org.springframework.context.annotation.Profile)1