Error redis clients jedis HostAndPort cant resolve localhost address

Des*_*ond 5 java redis spring-boot

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
Run Code Online (Sandbox Code Playgroud)

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;
    }
}
Run Code Online (Sandbox Code Playgroud)

Ran*_*niz 4

这个错误似乎已于6 月 15 日在 Jedis 中修复,因此应该包含在下一个版本中。

同时,您始终可以构建最新的主版本并在项目中使用该 JAR。只需记住在您的项目中包含 Jedis 的依赖项即可。

要从最新的 Jedis master(目前版本为 3.0.0-SNAPSHOT)构建 JAR:

$ 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/
Run Code Online (Sandbox Code Playgroud)

包含依赖项的示例build.gradle片段:

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"
}
Run Code Online (Sandbox Code Playgroud)

如果您想使用最新版本,只在顶部添加补丁,您可以将其选择到 2.9.0 标签,如下所示:

$ git clone https://github.com/xetorthio/jedis.git
$ cd jedis
$ git checkout jedis-2.9.0
$ git cherry-pick 42a6523041e710087640ceaab11d3abcd34f3a72
Run Code Online (Sandbox Code Playgroud)

$ git mergetool这将导致您必须合并的冲突,但是 kdiff3 自动为我解决了所有冲突,因此根据您使用的合并工具,除了运行并按 [enter]之外,您可能不需要执行任何操作。

解决冲突后,您只需按上述方式构建,但最终会得到一个名为jedis-2.9.0-SNAPSHOT.jar的 JAR 。