all. I implement findBy("name","password") at node_redis module, following this.
user.js
// return user find by name and password.
User.findBy = function(name,password){
console.log("calllelelelelll");
var res;
db.lrange("users",0,-1,function(err,users){
users.forEach(function(item){
var u = JSON.parse(item);
if ((u.name == name) && (u.password == password)){
res = u;
}
});
console.log(res);
return res;
});
};
###app.js
User.findBy(user.name,user.password);
However,User.findBy(user.name,user.password) function return undefined , console.log(res) is logged
like {name: "nobinobiru",password: "harashin0219"}
I wonder why findBy function return res is undefined ,but console.log(res)
is work correctly. Please help.
Thanks in advance.