I'm going crazy with a problem that I can not find a solution for. I can not return values from inside a query to Redis. I'm using the Redis client for NodeJS node_redis ( link ).
The problem is this: I wrote a function to get the connection status of a user and return it to be used in another function.
//CHECK USER STATUS
exports.checkUserStatus = function(uid){
redis.multi()
.sismember('users:online',uid)
.sismember('users:iddle', uid)
.sismember('users:out', uid)
.sismember('users:locked', uid)
.exec(function(err, res){
res.forEach(function(res, index){
if(res != 0){
switch(index){
case 0:
return 'online';
break;
case 1:
return 'iddle';
break;
case 2:
return 'out';
break;
case 3:
return 'locked';
break;
default:
return 'offline';
}
}
});
})
}
But, the function does not return anything! If I replace the "return" line with a "console.log ()", it works! but, I do not need a console output, I need to capture the value in a variable, in an external function!
I also tried to create a variable within the function but, outside the query, fill it in the query and then export it from outside the query but, it does not work.
Another thing I tried to do was add the statement "return" at the beginning of the query (something that appears in the driver's documentation), but, it always returns TRUE, which is not the value of the query but it ended up run.
Does anyone know how to do this?
Greetings and thanks!