【发布时间】:2017-04-17 08:35:48
【问题描述】:
我使用cluster-node-cache 和以下代码。
var obj = { my: "Special", variable: 42 };
cache.set("myKey", obj).then(function(result) {
console.log(result.err);
console.log(result.success);
cache.get("myKey").then(function(result2) {
console.log(result2.err);
console.log(result2.success);
});
});
这导致了以下输出
null
true
null
undefined
当然,有了这个结果,cluster-node-cache 不是集群缓存需求的解决方案。
请提出最佳解决方案以及为什么该解决方案是最好的?
【问题讨论】:
-
所写的代码甚至没有意义;你要求
result2.success是undefined。根据节点缓存文档,get的结果是具有err和value键的对象。如果不出意外,我至少建议在决定它是否适合您之前遵循实际的 API。 -
嗨@DaveNewton 我已经按照cluster-node-cache github页面的示例代码。我知道回调中应该有 err 对象,但是库的 github 页面中的示例说明了其他方式。
-
嗨@DaveNewton,请看一下这个例子.. myCache.get(["keyA", "keyB"]).then(function(results) { if(results.err) { console.日志(results.err); } else { console.log(results.value); } }); ...
-
嗨@DaveNewton,请查看您提供的链接中的示例代码(在检索密钥(GET):标题)...... eyCache.get(“myKey”)。然后(函数(结果) { if(results.err) { console.log(results.err); } else { console.log(results.value.myKey); } }); ...这里没有错误对象!! ..你的时间我很充实。
标签: express node-cluster