Key设计
全局相关的key:
表名 |
global |
|
列名 |
操作 |
备注 |
Global:userid |
incr |
产生全局的userid |
Global:postid |
Incr |
产生全局的postid |
用户相关的key(表):
表名 |
user |
||
Userid |
Username |
Password |
Authsecret |
3 |
Test3 |
1111111 |
#U*Q(%_ |
用户注册:
/**
* 用户注册信息
*/
public function userRegister()
{
$redis = RedisInstance::MasterInstance();
$redis->select(10);
$username = 'tinywan'.mt_rand(0000,8888);
$password = '123456';
if($redis->get('user:username:'.$username.':userid')){
exit('该用户名没有被使用');
}
//获取全局userId
$userId = $redis->incr('global:userid');
$redis->set('user:userId:'.$userId.':username',$username);
$redis->set('user:userId:'.$userId.':password',$password);
$redis->set('user:username:'.$username.':userid',$userId);
}
用于登录:
/**
* 用于登录信息
*/
public function userLogin()
{
$redis = RedisInstance::MasterInstance();
$redis->select(10);
$username = 'tinywan8165';
$password = '123456';
$uid = $redis->get('user:username:'.$username.':userid');
if($uid == false){
exit('该用户名不存在');
}
$oldpwd = $redis->get('user:userId:'.$uid.':password');
if($password != $oldpwd){
exit('密码错误');
}
echo '登录成功,跳转';
homePrint($uid);
}
表名 |
global |
|
列名 |
操作 |
备注 |
Global:userid |
incr |
产生全局的userid |
Global:postid |
Incr |
产生全局的postid |