function getRandomName(namesList) { var realname = ""; client.get('userlist’, function (error, res) { var list = JSON.parse(res); var pos = Math.round(Math.random() * (list.length - 1)); var oo = list[pos]; realname = "[" + oo.user_code + "]" + oo.real_name; console.log(‘realname–’ + realname); }); return realname; };
我这个是从REDIS缓存中随机获取一个用户名字,这东西搞了我半天啦,都不知道怎么弄,真是头疼,不知道你们是怎么处理这样的问题的?
3 回复
function getRandomName(namesList, callback) { var realname = ""; client.get('userlist’, function (error, res) { var list = JSON.parse(res); var pos = Math.round(Math.random() * (list.length - 1)); var oo = list[pos]; realname = "[" + oo.user_code + "]" + oo.real_name; return callback(realname); }); };