【发布时间】:2014-11-25 15:08:06
【问题描述】:
我编写了下面的代码,试图将视频收集到一个数组中然后返回。代码是错误的但我想不出正确的方法来做到这一点。
var redis = require('redis');
var client = redis.createClient();
app.get('/topvideos', function(req, res){
res.type('application/json');
var topvideos = [];
client.hkeys("topvideos", function(err,replies) {
console.log("Results for video:");
console.log(replies.length + " videos:");
replies.forEach(function (reply, i) {
client.hget("topvideos",i, function (err, reply) {
console.log(i + ": " + reply );
topvideos.push(reply);
});
});
}
var string = JSON.stringify(topvideos)
res.send(string);
});
有没有我可以遵循的优雅模式?
【问题讨论】:
-
@Scimonster - 这与其他问题类似,但该答案并没有真正告诉他们如何解决这个更复杂的情况。
-
您在寻找hgetall吗?
标签: node.js