gpt4 book ai didi

java - 检查连接 Redis

转载 作者:IT王子 更新时间:2023-10-29 06:01:17 25 4
gpt4 key购买 nike

我正在使用 Jedis 客户端在 Java 中使用 Redis。我正在创建一个 JedisPool 并想知道连接是否成功,有没有一种方法可以在不获取对象的情况下做到这一点?

最佳答案

您可以尝试从JedisPool 中获取Jedis 资源。如果未建立连接,将抛出 JedisConnectionException:

JedisPool pool = new JedisPool(...);
try {
Jedis jedis = pool.getResource();
// Is connected
} catch (JedisConnectionException e) {
// Not connected
}

关于java - 检查连接 Redis,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25236198/

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