我有以下生成错误的代码:
leagueclient.hgetall userLeagueKey, getLeagueInfo
我已经验证了 key 是正确的,并且 getLeagueInfo 正确执行并返回了正确的值,但在这两者之间我得到了 Cannot read property 'length' of undefined。调试说它在 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
所以错误发生在发送请求并得到结果之后。
知道是什么导致了错误,或者最好的调试方法吗?
最佳答案
这里的问题原来是试图从函数返回结果而不是通过回调传递结果。我确信这是使用 node 的新程序员的常见问题,所以我想我会提到它。所有依赖于外部访问的函数都必须使用回调。
关于node.js - 无法读取 node_redis hgetall 函数中未定义的属性 'length',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13173166/