首页 新闻 赞助 找找看

node 异步调用问题

0
悬赏园豆:30 [已解决问题] 解决于 2015-11-10 13:10

自学node对异步调用不是很明白  

var config = require('../config');

var redis = require("mredis"),
client = redis.createClient(config.redis_port, config.connection_redis);

client.set("1", "hello word!!", function (err, reply) {
console.log(reply);
client.expire('1', 1200);
});
client.set("2", "hello word2!!", function (err, reply) {
console.log(reply);
client.expire('2', 1200);
});
client.set("3", "hello word3!!", function (err, reply) {
console.log(reply);
client.expire('3', 1200);
});
client.set("4", "hello word4!!", function (err, reply) {
console.log(reply);
client.expire('4', 1200);
});

client.keys('*', function (err, reply) {
var ccc='';
var array =[ '3', '4', '1', '2' ];
for (i = 0; i < array.length; i++) {

client.get(array[i], function (err, ddd) {

ccc+=ddd;
});
}
console.dir(ccc);
});
代码是这样

我想最后for循坏结束后得到
hello word!!+hello word!2!+hello word!!3+hello word4!!

我应该怎么修改呢
高分悬赏
半哭半笑半颗心°的主页 半哭半笑半颗心° | 初学一级 | 园豆:3
提问于:2015-09-04 08:38
< >
分享
最佳答案
0

刘宏玺代码都给你贴了,你还要重新提一个,牛!

收获园豆:30
稳稳的河 | 老鸟四级 |园豆:4216 | 2015-09-04 12:48
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册