【发布时间】:2014-08-29 09:10:59
【问题描述】:
一个应用正在使用 meteor-redis 包运行 redis 查询,有时可能需要 30 秒才能返回 10 万个结果。在这段等待时间内,Meteor 在等待查询结果时会冻结并占用 100% 的 CPU。
var client = redis.createClient(port, url)
client.zrangebyscoreSync = Meteor._wrapAsync(client.zrangebyscore)
client.zrangebyscoreSync(['game:scores', '', '+inf'], function(err, scores) {
_.each(scores, function(score, player) {
var doc = { ... }
Scores.insert(doc)
})
})
问题: 有没有办法让 Meteor 在等待 redis 返回庞大的数据集时做点别的事情?如果client.zrangebyscore 没有被Meteor._wrapAsync 包裹,Meteor 会抛出错误
Error: Meteor code must always run within a Fiber. Try wrapping callbacks that you pass to non-Meteor libraries with Meteor.bindEnvironment.
跟踪将其指向Scores.insert(doc) 行。
【问题讨论】:
-
由于您正在尝试使用 Redis,不知道您是否会对我正在研究的 Meteor-Redis 集成感兴趣:groups.google.com/forum/#!topic/meteor-core/Jl5Jt739wdA
标签: javascript node.js meteor redis node-redis