node.js - 无法读取 node_redis hgetall 函数中未定义的属性 'length'

标签 node.js coffeescript redis asynccallback node-redis

我有以下生成错误的代码:

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/

相关文章:

Django celery 任务重复 : can't lock DB?

node.js - 如何在 Node.js 中触发超时功能?

javascript - 如何读取刚刚使用 yeoman 写入的文件?

node.js - Swagger UI 不发送 url 参数

collections - 为什么 Meteor 提示集合的插入方法已经定义?

ruby-on-rails - 如何将 CoffeeScript 规范与 Jasmine-Rails 一起使用

node.js - Docker buildx 与 Apple M1 芯片上的 Node 应用程序 - standard_init_linux.go :211: exec user process caused "exec format error

node.js - 使用 Google oauth 访问时创建与登录

asp.net - 连接前检测Redis是否连接

redis - 如何列出所有Redis数据库?