www.qgnn.net > 如何判断 rEDis 连接是否有效

如何判断 rEDis 连接是否有效

>>> conn = redis.StrictRedis('1.2.3.4', 1234, socket_timeout=3) >>> conn.get('xxxxxxxxxxxxx') ...... redis.exceptions.ConnectionError: Error connecting to 1.2.3.4:1234. timed out. 回答不容易,希望能帮到您,满意请帮忙采纳一下,谢谢 !

调用redis客户端的ping方法。如果返回pong,则连接有效。如果抛出异常表示连接有问题。

只能靠超时来判断。 参考代码 var redispool = poolModule.Pool({ name : 'redis', create : function(callback) { var client = Redis.createClient(configs.dbconfig.dbredis.port, configs.dbconfig.dbredis.host); // client.connect(); cal...

>>> conn = redis.StrictRedis('1.2.3.4', 1234, socket_timeout=3) >>> conn.get('xxxxxxxxxxxxx') ...... redis.exceptions.ConnectionError: Error connecting to 1.2.3.4:1234. timed out.

>>> conn = redis.StrictRedis('1.2.3.4', 1234, socket_timeout=3) >>> conn.get('xxxxxxxxxxxxx') ...... redis.exceptions.ConnectionError: Error connecting to 1.2.3.4:123

参考代码: var redispool = poolModule.Pool({ name : 'redis', create : function(callback) { var client = Redis.createClient(configs.dbconfig.dbredis.port, configs.dbconfig.dbredis.host); // client.connect(); callback(null, clien...

>>> conn = redis.StrictRedis('1.2.3.4', 1234, socket_timeout=3) >>> conn.get('xxxxxxxxxxxxx') ...... redis.exceptions.ConnectionError: Error connecting to 1.2.3.4:1234. timed out.

我是通过这个方法来判断是否连通的private static bool Ping(RedisClient client){try{if (client.Ping()){return true;}else {return false;}}catch{return false;}}如果连接不同 Ping() 会有一点延迟,好像是内部已经实现了重连的判断,如果连...

网站地图

All rights reserved Powered by www.qgnn.net

copyright ©right 2010-2021。
www.qgnn.net内容来自网络,如有侵犯请联系客服。zhit325@qq.com