use of org.springframework.data.redis.connection.RedisStandaloneConfiguration 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.RedisStandaloneConfiguration in project jetcache by alibaba.
the class RedisSpringDataCacheTest method lettuceTest.
@Test
public void lettuceTest() throws Exception {
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory(new RedisStandaloneConfiguration("127.0.0.1", 6379));
connectionFactory.afterPropertiesSet();
doTest(connectionFactory);
}
Aggregations