我来自PHP背景,现在我正在尝试习惯Node.js的事件驱动范例。但是,我的代码很快变得混乱。下面我将程序代码与实际的Node.js Redis代码进行比较。我这样做了吗?
PROCEDURAL(pseude code)
if(!client.get("user:name:koen")) {
client.set("user:name:koen", "user:id:" + client.incr("count:users"));
}
EVENT DRIVEN(实际代码)
client.get("user:name:koen", function(err, res) {
if(!res){
client.incr("count:users", function(err, count){
client.set("user:name:koen", "user:id:" + count, function (err, res) {
callback(err, res);
});
});
}
});