var adduser = function (user, pwd, callback) {
var userid;
client.incr("userid", function (err, reply) {
userid = reply.toString();
});
client.lpush("user_id", userid, function (err, reply) {
if (!err) {
client.set("user_name_" + userid, user);
clinet.set("user_pwd_" + userid, pwd);
}
});
}
注册用户这样写对不对? 但是如果判断用户是否重复怎么写?
是不是这样写?
var adduser = function (user, pwd, callback) {
client.get("user_" + user, function (reply) {
if (reply == null) {//这里判断
var userid;
client.incr("userid", function (err, reply) {
userid = reply.toString();
});
client.lpush("user_id", userid, function (err, reply) {
if (!err) {
client.set("user_name_" + userid, user);
clinet.set("user_pwd_" + userid, pwd);
client.set("user_" + user, userid);//这里一加行
callback("注册成功");
}
});
}
else {
callback("用户已存在");
}
});
client.end();
}