I am using socket.io, redis for tracking users online/offline status. Here I am storing the no.of users with name as key with the pattern hub_id. I am able to get the number of users by just getting count of keys matching hub_ pattern. Now the key has value as status online or offline.
I am unable to get the no. users online or offline variable outside the for loop.
app.get('/test', function(req, res) {
client.keys('hub*', function (err, keys) {
console.log(keys.length);
for (var i=0; i<keys.length; i++){
client.hgetall(keys[i], function(err, reply) {
if(reply.status == "online"){
onlinehub++;
}
else if(reply.status == "offline"){
offlinehub++;
}
});
}
console.log(onlinehub +"-" +offlinehub)
});
});
via Karthikeyan Prakash
No comments:
Post a Comment