0

我有以下代码生成错误:

leagueclient.hgetall userLeagueKey, getLeagueInfo

我已经验证密钥是正确的,并且 getLeagueInfo 以正确的返回值正确执行,但在两者之间我得到了无法读取未定义的属性“长度”。调试说它在 hgetall 中。

我在 node_redis 中打开了调试消息

send 127.0.0.1:6379 id 2: *2
$7
hgetall
$14
userLeagueId:0

send_command buffered_writes: 0  should_buffer: false
true
Cannot read property 'length' of undefined
net read 127.0.0.1:6379 id 2: *6
$11
challengeId
$1
0
$10
leagueName
$5
Oatmo
$22
currentDiscussionEntry
$1
2

所以错误发生在发送请求并得到结果之后。

知道什么可能导致错误,或者是调试它的最佳方法吗?

4

1 回答 1

1

这里的问题是试图从函数返回结果,而不是通过回调传递结果。我确信这是使用 node 的新程序员的常见问题,所以我想我会提到它。所有依赖于外部访问的函数都必须使用回调。

于 2012-11-13T06:46:23.070 回答