reids的hash实现用户数据的增删改查
1.用户注册
public function saveuser() {
$username = $_POST ['username'];
$password = md5 ( $_POST ['password'] );
$age = $_POST ['age'];
$addtime = time ();
$uid = $this->redis->incr ( 'userid' );
$this->redis->hmset ( 'user:' . $uid, array ('uid' => $uid, 'username' => $username, 'password' => $password, 'age' => $age, 'addtime' => $addtime ) );
$this->redirect('Cache/userlist');
}
2.用户列表
public function userlist() {
$uid = $this->redis->get ( 'userid' );
for($i = 1; $i <= $uid; $i ++) {
$users [] = $this->redis->hgetall ( 'user:' . $i );
}
$userss=array_filter($users);
$this->users=$userss;
$this->display();
}
3.删除一个用户
public function deluser(){
$uid=$_GET['uid'];
$this->redis->delete('user:'.$uid);
$this->redirect('Cache/userlist');
}
4.修改一个用户数据
public function edituser(){
$uid=$_GET['uid'];
$user=$this->redis->hgetall('user:'.$uid);
$this->user=$user;
$this->display();
}
public function saveedituser(){
$uid=$_POST['uid'];
$username=$_POST['username'];
$age=$_POST['age'];
$this->redis->hmset('user:'.$uid,array('username'=>$username,'age'=>$age));
$this->redirect('Cache/userlist');
}