函数不返回数据
我有以下代码,
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 中特定用户名的值,但它没有返回,请帮助查找它没有返回的原因。 我应该怎么做才能获得价值回报?
I have the following code
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);
});
i have created a getuser function to return the value of particular username in userhash but it is not returning please help in finding why it is not returning .
what should i do to get the value return ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您在同步 getUser 函数中进行异步调用时,您正在混合同步和异步模式。您需要使 getUser 函数异步 - 例如:
You're mixing sync and async patterns when you make an async call in your sync getUser function. You need to make your getUser function async - e.g: