我正在使用ioredis,我想在下面的示例中返回路径和值,一直到匿名函数。
console.log(
function (jsonGraphArg) {
return Redis.hget(jsonGraphArg[0], jsonGraphArg[1], function(error, result){
result = JSON.parse(result);
return {
path: [jsonGraphArg[0], jsonGraphArg[1], jsonGraphArg[2][0]],
value: result[jsonGraphArg[2][0]]
};
});
}
);
我希望console.log()
中的结果是这样的:
{
path: "something",
value: "something else"
}
但相反它给了我:
{
_bitField: 1,
_fulfillmentHandler0: [Function: successAdapter],
_rejectionHandler0: [Function: errorAdapter],
_progressHandler0: undefined,
_promise0: [Function],
_receiver0: [Circular],
_settledValue: undefined
}
答案 0 :(得分:0)
答案在promis
console.log(
function (jsonGraphArg) {
return Redis.hget(jsonGraphArg[0], jsonGraphArg[1]).
then(function(result){
result = JSON.parse(result);
return {
path: [jsonGraphArg[0], jsonGraphArg[1], jsonGraphArg[2][0]],
value: result[jsonGraphArg[2][0]]
};
});
}
);