检查连接Redis [英] Check connection Redis
本文介绍了检查连接Redis的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 Jedis 客户端在 Java 中使用 Redis.我正在创建一个 JedisPool,想知道连接是否成功,有没有办法在不获取对象的情况下做到这一点?
I am using the Redis in Java using the Jedis client. I am creating a JedisPool and would like to know if the connection is successful, is there a way of doing this without fetching an object?
推荐答案
您可以尝试从 JedisPool
获取 Jedis
资源.如果连接尚未建立,将抛出 JedisConnectionException
:
You can attempt to get the Jedis
resource from the JedisPool
. A JedisConnectionException
will be thrown if a connection has not been established:
JedisPool pool = new JedisPool(...);
try {
Jedis jedis = pool.getResource();
// Is connected
} catch (JedisConnectionException e) {
// Not connected
}
这篇关于检查连接Redis的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文