0

Currently I'm using Redis that is provided by PCF. I'm connecting to it using JedisConnectionFactory from spring-data-redis providing needed configs like this:

@Configuration
public class RedisConfig {

    @Bean
    public JedisConnectionFactory jedisConnectionFactory() {
        final JedisConnectionFactory jedisConFactory = new JedisConnectionFactory();
        jedisConFactory.setHostName("pivotal-redis-host");
        jedisConFactory.setPort(1234);
        jedisConFactory.setPassword("mySecretPassword");
        return jedisConFactory;
    }
}

spring-cloud-config provides AbstractCloudConfig class that can be used to configure various connections. Is there any noticeable benefits one must use it instead of JedisConnectionFactory? Looks like less configs is needed to be provided, but is there any other reason?

public class RedisCloudConfig extends AbstractCloudConfig {
    @Bean
    public RedisConnectionFactory redisConnection() {
        return connectionFactory().redisConnectionFactory();
    }
}

Thanks in advance.

Oleg Kuts
  • 769
  • 1
  • 13
  • 26

2 Answers2

2

The main difference with Spring Cloud Connectors is that it's reading the service information from the Redis service that you bound to your application on Cloud Foundry. It then automatically configures the Redis connection based on that dynamically bound information.

Your example of using JedisConnectionFactory as well as @avhi's solution are placing the configuration information directly into either your source code or application configuration files. In this case, if your service changes then you'd need to reconfigure your app and run cf push again.

With Spring Cloud Connectors, you can change services by simply unbinding and binding a new Redis service through CF, and running cf restart.

Daniel Mikusa
  • 13,716
  • 1
  • 22
  • 28
1

In my opinion even you don't need to define @Bean configuration specifically.

You can simply use auto configuration by providing Redis server details in application.yml or application.properties simply.

spring:
  redis:
    host: pivotal-redis-host
    port: 1234
    password: mySecretPassword 
Avhi
  • 806
  • 2
  • 15
  • 29
  • thanks for your reply. I know that I could move config data to app.yml file, but did not know there are specific spring.redis properties for that purposes. – Oleg Kuts May 08 '18 at 15:36
  • Please "Mark as Answer" on the post If it helps you, this can be beneficial to other community members. – Avhi May 24 '18 at 17:19