node.js使用redis也是应该配置连接池的。
node.js中配置连接池可以考虑使用generic-pool模块
官网:http://github.com/coopernurse/node-pool
var poolModule = bbPromise.promisifyAll(require('generic-pool'));
var redispool = poolModule.Pool({
name : 'redis',
create : function(callback) {
var client = Redis.createClient(configs.dbconfig.dbredis.port,
configs.dbconfig.dbredis.host);
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 ;