我有以下代码
var redis = require("redis"),
client = redis.createClient();
var getuser = function(username) {
var userhash={};
client.hgetall("users."+username, function(err, user) {
userhash=user;
});
return userhash;
};
user_rahul = {
username: 'rahul',
queueno: 1,
sessionId: '6604353811126202'
};
user_namita = {
username: 'namita',
sessionId:'2'
};
client.hmset('users.rahul', user_rahul);
client.hmset('users.namita', user_namita);
var username = "rahul"; // From a POST perhaps
var user1=getuser(username);
console.log(user1);
client.hgetall("users." + username, function(err, user) {
console.log(user);
});
我创建了一个 getuser 函数来返回 userhash 中特定用户名的值,但它没有返回请帮助找出它没有返回的原因。我应该怎么做才能获得价值回报?