比如用户表 id,username,pwd很简单的3个字段
1 var adduser = function (user, pwd, callback) { 2 var userid; 3 client.incr("userid", function (err, reply) { 4 userid = reply.toString(); 5 }); 6 client.lpush("user_id", userid, function (err, reply) { 7 if (!err) { 8 client.set("user_name_" + userid, user); 9 clinet.set("user_pwd_" + userid, pwd); 10 11 } 12 }); 13 }
这样 写对不对?
如果 对怎么判断用户重复注册,是不是这样?
1 var adduser = function (user, pwd, callback) { 2 client.get("user_" + user, function (reply) { 3 if (reply == null) {//这里判断 4 var userid; 5 client.incr("userid", function (err, reply) { 6 userid = reply.toString(); 7 }); 8 client.lpush("user_id", userid, function (err, reply) { 9 if (!err) { 10 client.set("user_name_" + userid, user); 11 clinet.set("user_pwd_" + userid, pwd); 12 client.set("user_" + user, userid);//这里一加行 13 callback("注册成功"); 14 } 15 }); 16 } 17 else { 18 callback("用户已存在"); 19 } 20 }); 21 client.end(); 22 23 }