redis 用户表3个字段id,username,pwd
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();
}
1 回复
可以这样,一般的注册 入库的时候都先查一次。。