【问题标题】:JedisPool Connection Refused Spring BootJedisPool 连接拒绝 Spring Boot
【发布时间】:2021-02-23 18:43:51
【问题描述】:

我有一个小型 Spring Boot 应用程序,我正在尝试使用 Jedis 客户端与 Redis 集成。

我将 Jedis 池设置为指向本地运行的 Redis docker 容器。

    @Bean
public JedisPool jedisPool() {
    JedisPool jedisPool = null;
    try {
        URI redisUri = new URI("redis://localhost:6379");
        jedisPool = new JedisPool(poolConfig(), redisUri, 20000, null, null, null);
    } catch (URISyntaxException e) {
        logger.error("Failed to create the redis pool: ", e);
    }
    return jedisPool;
}

我有一个 RedisService,它使用 JedisPool 并针对 Redis 服务器执行事务。

 @Autowired
JedisPool jedisPool;

@Override
public String retrieve(String key) {
    Jedis jedis = jedisPool.getResource();
    String json = jedis.get(key);
    jedis.close();
    return json;
}

@Override
public void store(String key, String value) {
    Jedis jedis = jedisPool.getResource();
    jedis.set(key, value);
    jedis.expire(key, keyExpire);
    jedis.close();
}

运行应用程序时出现此异常

redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool

Caused by: redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refused (Connection refused)

我可以通过redis-cli 连接到 Redis 服务器,但不能通过我的 Spring Boot 应用程序。

关于如何解决这个问题的任何想法?

【问题讨论】:

    标签: java spring-boot redis spring-data-redis


    【解决方案1】:

    尝试使用 http://localhost:6379 代替您当前的 URI

    【讨论】:

    • 同样抛出的异常
    猜你喜欢
    • 1970-01-01
    • 2020-12-31
    • 1970-01-01
    • 1970-01-01
    • 2020-01-19
    • 2018-09-22
    • 2022-01-11
    • 2019-06-06
    • 1970-01-01
    相关资源
    最近更新 更多