spool连接拒绝spring boot

ntjbwcob  于 2021-06-09  发布在  Redis
关注(0)|答案(1)|浏览(381)

我有一个小的spring启动应用程序,我正在尝试使用jedis客户机与redis集成。
我设置了绝地武士池,指向本地运行的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 但不是从我的 Spring 启动应用程序。
关于如何解决这个问题有什么想法吗?

rqcrx0a6

rqcrx0a61#

尝试使用http://localhost:6379替换当前uri

相关问题