如何判断 redis 连接是否有效
1个回答
展开全部
只能靠超时来判断。
参考代码
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, client);
},
destroy : function(client) { client.quit(); },
max : 10,
// optional. if you set this, make sure to drain() (see step 3)
min : 2,
// specifies how long a resource can stay idle in pool before being removed
idleTimeoutMillis : 30000
// if true, logs via console.log - can also be a function
//log : true
});
function getRedisClient() {
return redispool.acquireAsync().disposer(function(client, promise) {
console.log("redispool.release(client)")
redispool.release(client);
});
}
dbs.redisclient = getRedisClient ;
--------------
检测redisclient是否为空
参考代码
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, client);
},
destroy : function(client) { client.quit(); },
max : 10,
// optional. if you set this, make sure to drain() (see step 3)
min : 2,
// specifies how long a resource can stay idle in pool before being removed
idleTimeoutMillis : 30000
// if true, logs via console.log - can also be a function
//log : true
});
function getRedisClient() {
return redispool.acquireAsync().disposer(function(client, promise) {
console.log("redispool.release(client)")
redispool.release(client);
});
}
dbs.redisclient = getRedisClient ;
--------------
检测redisclient是否为空
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |