node.js - NodeJS async module + redis -


im using async model in node along redis.

my code:

async.each(data, function(n, done) {         redisclient.llen("user:" + n + ":active", function(err, numbactive) {             if(!err) {                 console.log("[checking].... " + n + " numb::::: " + numbactive);                 globalnumbactive += numbactive;                 done(globalnumbactive);             } else {                 done(err, 0);             }         });              }, function(err, globalnumbactive) {     console.log("globals --> " + globalnumbactive);     return callback(globalnumbactive); });  

data above contains:

['231', '323', '323'] 

i want check each of userids in user:user_id:active list, sum them , return.

right above grabs first , returns.

any ideas i'm doing wrong?

what if second argument of main callback removed? following snippet works me.

// assume 2 lists have been created in way below. // redisclient.lpush('user:231:active', 'john', 'adam'); // redisclient.lpush('user:323:active', 'sam');  var data = ['231', '323', '323']; var globalnumactive = 0; async.each(data, function(n, callback) {     redisclient.llen('user:' + n + ':active', function(err, numactive) {         if (!err) {             globalnumactive += numactive;             console.log('user id: ' + n + '\tactive #: ' + numactive + '\ttotal active #: ' + globalnumactive);             callback(null);         } else {             callback(err);         }     }); }, function(err) {     console.log('total active #: ' + globalnumactive); }); 

the output is

user id: 231    active #: 2    total active #: 2 user id: 323    active #: 1    total active #: 3 user id: 323    active #: 1    total active #: 4 total active #: 4 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -