gpt4 book ai didi

java - 错误 redis 客户端 jedis HostAndPort 无法解析本地主机地址

转载 作者:IT王子 更新时间:2023-10-29 05:59:27 25 4
gpt4 key购买 nike

我在 AWS 上托管我的应用程序。我已经如下配置了我的属性文件

spring.redis.host = {AWS 主机端点}spring.redis.port = 6379

我的应用程序之间的连接有效。但是,spring 在连接到 aws 主机端点之前总是尝试先连接到本地主机,因此抛出错误。错误如下所示。

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

请问如何解决,谢谢

编辑下面显示了我的 Redis 配置类

@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;
}
}

最佳答案

这个错误似乎是fixed 6 月 15 日在绝地武士中,所以应该包含在下一个版本中。

与此同时,您始终可以构建最新的 master 并在您的项目中使用该 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/

包含依赖项的 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"
}

如果你想使用最新版本,只在顶部添加补丁,你可以像这样将它挑选到 2.9.0 标签中:

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

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

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

关于java - 错误 redis 客户端 jedis HostAndPort 无法解析本地主机地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44252750/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com