2
我試圖從redis中刪除大量的密鑰(〜20M),並且出現錯誤RangeError:由於過度遞歸導致最大調用堆棧大小超過調用。 我試圖在遞歸調用中使用process.nextTick(),但仍然收到相同的錯誤。RangeError:超過最大調用堆棧大小 - nodejs,redis
count = "100";
cursor = "0";
function scanRedis(key, callback){
redisClient.scan(cursor, "MATCH", key, "COUNT", count, function(err, reply){
if(err){
throw err;
}
cursor = reply[0];
if(cursor === "0" && reply[1].length === 0){
return callback(false, true);
}else if(cursor === "0" && reply[1].length > 0){
redisClient.del(reply[1], function(deleteErr, deleteSuccess){
return callback(false, true);
});
}else{
if(reply[1].length > 0){
delCount += reply[1].length;
//console.log(reply[1]);
redisMulti.del(reply[1]);
}
redisMulti.exec(function(deleteErr, deleteSuccess){
process.nextTick(function(){
scanRedis(key, function(err, reply){ //getting an error here
callback(false, true);
});
});
});
}
});
};