Search in sources :

Example 6 with LettuceConnectionFactory

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

the class RedisAutoConfigurationTests method testRedisConfigurationUsePoolByDefault.

@Test
void testRedisConfigurationUsePoolByDefault() {
    Pool defaultPool = new RedisProperties().getLettuce().getPool();
    this.contextRunner.withPropertyValues("spring.redis.host:foo").run((context) -> {
        LettuceConnectionFactory cf = context.getBean(LettuceConnectionFactory.class);
        assertThat(cf.getHostName()).isEqualTo("foo");
        GenericObjectPoolConfig<?> poolConfig = getPoolingClientConfiguration(cf).getPoolConfig();
        assertThat(poolConfig.getMinIdle()).isEqualTo(defaultPool.getMinIdle());
        assertThat(poolConfig.getMaxIdle()).isEqualTo(defaultPool.getMaxIdle());
        assertThat(poolConfig.getMaxTotal()).isEqualTo(defaultPool.getMaxActive());
        assertThat(poolConfig.getMaxWaitDuration()).isEqualTo(defaultPool.getMaxWait());
    });
}
Also used : LettuceConnectionFactory(org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory) Pool(org.springframework.boot.autoconfigure.data.redis.RedisProperties.Pool) Test(org.junit.jupiter.api.Test)

Example 7 with LettuceConnectionFactory

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

the class RedisAutoConfigurationTests method testRedisConfigurationWithClusterAndAuthentication.

@Test
void testRedisConfigurationWithClusterAndAuthentication() {
    List<String> clusterNodes = Arrays.asList("127.0.0.1:27379", "127.0.0.1:27380");
    this.contextRunner.withPropertyValues("spring.redis.username=user", "spring.redis.password=password", "spring.redis.cluster.nodes[0]:" + clusterNodes.get(0), "spring.redis.cluster.nodes[1]:" + clusterNodes.get(1)).run((context) -> {
        LettuceConnectionFactory connectionFactory = context.getBean(LettuceConnectionFactory.class);
        assertThat(getUserName(connectionFactory)).isEqualTo("user");
        assertThat(connectionFactory.getPassword()).isEqualTo("password");
    });
}
Also used : LettuceConnectionFactory(org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory) Test(org.junit.jupiter.api.Test)

Example 8 with LettuceConnectionFactory

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

the class RedisAutoConfigurationTests method testOverrideUrlRedisConfiguration.

@Test
void testOverrideUrlRedisConfiguration() {
    this.contextRunner.withPropertyValues("spring.redis.host:foo", "spring.redis.password:xyz", "spring.redis.port:1000", "spring.redis.ssl:false", "spring.redis.url:rediss://user:password@example:33").run((context) -> {
        LettuceConnectionFactory cf = context.getBean(LettuceConnectionFactory.class);
        assertThat(cf.getHostName()).isEqualTo("example");
        assertThat(cf.getPort()).isEqualTo(33);
        assertThat(getUserName(cf)).isEqualTo("user");
        assertThat(cf.getPassword()).isEqualTo("password");
        assertThat(cf.isUseSsl()).isTrue();
    });
}
Also used : LettuceConnectionFactory(org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory) Test(org.junit.jupiter.api.Test)

Example 9 with LettuceConnectionFactory

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

the class RedisAutoConfigurationTests method testRedisConfigurationWithClientName.

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

Example 10 with LettuceConnectionFactory

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

the class RedisAutoConfigurationTests method testRedisConfigurationWithSentinelAndDatabase.

@Test
void testRedisConfigurationWithSentinelAndDatabase() {
    this.contextRunner.withPropertyValues("spring.redis.database:1", "spring.redis.sentinel.master:mymaster", "spring.redis.sentinel.nodes:127.0.0.1:26379, 127.0.0.1:26380").run((context) -> {
        LettuceConnectionFactory connectionFactory = context.getBean(LettuceConnectionFactory.class);
        assertThat(connectionFactory.getDatabase()).isEqualTo(1);
        assertThat(connectionFactory.isRedisSentinelAware()).isTrue();
    });
}
Also used : LettuceConnectionFactory(org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory) Test(org.junit.jupiter.api.Test)

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