自学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!!
我应该怎么修改呢
高分悬赏
刘宏玺代码都给你贴了,你还要重新提一个,牛!