Search code examples
springspring-bootredisspring-data-redisjedis

How to connect Redis cloud with JedisConnectionFacory


I have a spring boot app. I want to connect to Redis cloud server by using jedisconnectionfactory but I couldn't do that. Actually it works when I use local Redis server.

The Redis configuration I wrote is on below.

@Configuration
public class RedisConfig {

    @Bean
    public JedisConnectionFactory connectionFactory() {
        RedisStandaloneConfiguration configuration = new RedisStandaloneConfiguration();
        configuration.setHostName( "redis-cli -u redis://redis-19735.c1.us-east1-2.gce.cloud.redislabs.com");
        configuration.setPort(19735);
        configuration.setUsername("<username_goes_here>");
        configuration.setPassword("<password_goes_here>");
        return new JedisConnectionFactory(configuration);
       
        
    }
    @Bean
    public RedisTemplate<String, Object> redisTemplate(){
        RedisTemplate<String,Object> template = new RedisTemplate<>();
        template.setConnectionFactory(connectionFactory());
        template.setKeySerializer(new StringRedisSerializer());
        template.setValueSerializer(new GenericJackson2JsonRedisSerializer());
        return template;
        
    }

}

Also You can see my Redis cloud database on below too.

enter image description here

Can you help me about it how can I connect it. I tried to connect Redis cloud database with using jedisconnectionfactory but I couldn't do it.


Solution

  • Put the hostname simply redis-19735.c1.us-east1-2.gce.cloud.redislabs.com.