Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error redis clients jedis HostAndPort cant resolve localhost address

Tags:

I am hosting my application on AWS. I have configured my property files as follow below

spring.redis.host = {AWS host endpoint} spring.redis.port = 6379

Connection between my application works. However, spring attempts to always conneect to local host first before connecting to the aws host endpoint, therefore throwing the error. The error is shown below.

2017-05-30 10:37:58.203 [main] ERROR redis.clients.jedis.HostAndPort:
 cant resolve localhost address

How do i resolve this please thank you

EDIT Below shows my Redis config class

@Configuration
@EnableCaching
public class RedisCacheConfig {

    final Logger logger = LoggerFactory.getLogger(RedisCacheConfig.class);

    JedisConnectionFactory connectionFactory;

    @Autowired
    public RedisCacheConfig(JedisConnectionFactory connectionFactory) {
        this.connectionFactory = connectionFactory;
    }

    @Bean
    @Autowired
    public CacheManager getCacheManager(CacheExpiration expiration) {
        RedisCacheManager manager = new RedisCacheManager(getRedisTemplate());
        manager.setExpires(expiration.getMapper());
        //expiration.getMapper();
        return manager;
    }

    @Bean
    public RedisTemplate getRedisTemplate() {
        RedisTemplate template = new RedisTemplate();
        template.setConnectionFactory(connectionFactory);
        template.setValueSerializer(new GenericJackson2JsonRedisSerializer());
        return template;
    }
}
like image 324
Ninja Dude Avatar asked May 30 '17 03:05

Ninja Dude


1 Answers

This bug seems to have been fixed in Jedis on June 15 so should be included in the next release.

In the meantime you can always build the latest master and use that JAR in your project. Just remember to include the dependencies for Jedis in your project.

To build a JAR from the latest Jedis master (which is at version 3.0.0-SNAPSHOT at the moment):

$ git clone https://github.com/xetorthio/jedis.git
$ cd jedis
$ mvn -Dmaven.test.skip=true package
$ mkdir -p /path/to/your/project/lib
$ cp target/jedis-3.0.0-SNAPSHOT.jar /path/to/your/project/lib/

Example build.gradle snippet with included dependencies:

dependencies {
    file project.file("lib/jedis-3.0.0-SNAPSHOT.jar")
    compile "org.slf4j:slf4j-api:1.7.22"
    compile "org.apache.commons:commons-pool2:2.4.2"
}

If you want to use the latest release with just the patch added on top you can cherry pick it to the 2.9.0 tag like this:

$ git clone https://github.com/xetorthio/jedis.git
$ cd jedis
$ git checkout jedis-2.9.0
$ git cherry-pick 42a6523041e710087640ceaab11d3abcd34f3a72

This will result in conflicts which you'll have to merge, however kdiff3 automatically solved all the conflicts for me so depending on what mergetool you're using you may not have to do anything other than run $ git mergetool and press [enter].

After resolving the conflicts you just build as above but you'll end up with a JAR named jedis-2.9.0-SNAPSHOT.jar instead.

like image 91
Raniz Avatar answered Sep 21 '22 10:09

Raniz