我有以下代码:
client.keys("key_"+id, function (err, replies){
if (replies.length > 0){
client.sunion(replies,function (err, replies){
{...}
});
}else{...}
});
下面我有这个功能
pg.connect(conString, function(err, client) {some code});
但我想在第一段代码中执行pg.connect
而不是执行。...
如何最好地避免复制代码和内存泄漏,pg.connect
功能将是相同的{...}
。
通过复制代码,这将如下所示:
client.keys("key_"+id, function (err, replies){
if (replies.length > 0){
client.sunion(replies,function (err, replies){
pg.connect(conString, function(err, client) {some code});
});
}else{pg.connect(conString, function(err, client) {some code});}
});