use of org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory 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));
}
}
use of org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory in project spring-cloud-connectors by spring-cloud.
the class SpringData1RedisConnectionFactoryCreator method create.
@Override
public RedisConnectionFactory create(RedisServiceInfo serviceInfo, ServiceConnectorConfig serviceConnectorConfig) {
if (hasClass(JEDIS_CLASS_NAME)) {
SpringData1RedisConnectionFactoryConfigurer configurer = new SpringData1RedisConnectionFactoryConfigurer();
JedisConnectionFactory connectionFactory = new JedisConnectionFactory();
connectionFactory.setHostName(serviceInfo.getHost());
connectionFactory.setPort(serviceInfo.getPort());
connectionFactory.setPassword(serviceInfo.getPassword());
if (serviceConnectorConfig instanceof RedisConnectionFactoryConfig) {
configurer.configure(connectionFactory, (RedisConnectionFactoryConfig) serviceConnectorConfig);
} else {
configurer.configure(connectionFactory, (PooledServiceConnectorConfig) serviceConnectorConfig);
}
connectionFactory.afterPropertiesSet();
return connectionFactory;
} else if (hasClass(LETTUCE_CLASS_NAME)) {
SpringData1RedisLettuceConnectionFactoryConfigurer configurer = new SpringData1RedisLettuceConnectionFactoryConfigurer();
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory();
connectionFactory.setHostName(serviceInfo.getHost());
connectionFactory.setPort(serviceInfo.getPort());
connectionFactory.setPassword(serviceInfo.getPassword());
configurer.configure(connectionFactory, (RedisConnectionFactoryConfig) serviceConnectorConfig);
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));
}
}
use of org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory in project spring-boot by spring-projects.
the class RedisAutoConfigurationTests method testRedisConfigurationDisabledPool.
@Test
void testRedisConfigurationDisabledPool() {
this.contextRunner.withPropertyValues("spring.redis.host:foo", "spring.redis.lettuce.pool.enabled:false").run((context) -> {
LettuceConnectionFactory cf = context.getBean(LettuceConnectionFactory.class);
assertThat(cf.getHostName()).isEqualTo("foo");
assertThat(cf.getClientConfiguration()).isNotInstanceOf(LettucePoolingClientConfiguration.class);
});
}
use of org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory in project spring-boot by spring-projects.
the class RedisAutoConfigurationTests method testPasswordInUrlStartsWithColon.
@Test
void testPasswordInUrlStartsWithColon() {
this.contextRunner.withPropertyValues("spring.redis.url:redis://user::pass:word@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(":pass:word");
});
}
use of org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory in project spring-boot by spring-projects.
the class RedisAutoConfigurationTests method testRedisConfigurationWithDefaultTimeouts.
@Test
void testRedisConfigurationWithDefaultTimeouts() {
this.contextRunner.withPropertyValues("spring.redis.host:foo").run((context) -> {
LettuceConnectionFactory cf = context.getBean(LettuceConnectionFactory.class);
assertThat(cf.getHostName()).isEqualTo("foo");
assertThat(cf.getTimeout()).isEqualTo(60000);
assertThat(cf.getClientConfiguration().getClientOptions().get().getSocketOptions().getConnectTimeout().toMillis()).isEqualTo(10000);
});
}
Aggregations