我是nodejs的新手,也许没有一个事件系统应该如何工作。找不到错误。请指教。我需要一个简单的任务-检查标签,如果它不存在,则设置新的密钥和有关标签的信息。问题是-然后我第一次运行该脚本,它始终返回“键不存在”。检查redisdb键-它会创建很多标签这是我的代码
for (x = 0; x < rows.length; x++) {
if (rows[x].term_taxonomy_id != 1) {
var taxonomy = findOne(rterms, rows[x].term_taxonomy_id);
rc.exists('tag:' + taxonomy.name, function (err, rexists) {
if (rexists == false) {
rc.incr('tags:count', function (err, id) {
console.log(taxonomy.name+' not exists. result ' + rexists);
rc.set('tag:' + taxonomy.name,id);
rc.hmset('tag:' + id,
'id', id,
'title',taxonomy.name,
'url', taxonomy.slug
);
});//incr
}else{
console.log(taxonomy.name+' exists!'+rexists);
};
});//exists
};//ifrows
});
Run Code Online (Sandbox Code Playgroud)
这是另一个例子
var tags = [
"apple",
"tiger",
"mouse",
"apple",
"apple",
"apple",
"tiger",
"mouse",
"mouse",
];
var …Run Code Online (Sandbox Code Playgroud)