test.php
<?php
$redis = new Redis();
$redis->connect('127.0.0.1',6379);
?>
===========================
add.php
<form method='POST' action='reg.php'>
用户名:<input type='text' name='username'/>
密码:<input type='password' name='pwd'/>
年龄:<input type='text' name='age'/>
<input type='submit' value='提交'>
<input type='reset' value='重新填写'>
</form>
==============================
reg.php
<?php
require('test.php');
$username = $_POST['username'];
$pwd = $_POST['pwd'];
$age = $_POST['age'];
$uid = $redis->incr('userId');
$redis->hmset("user:".$uid,array('uid'=>$uid, 'username'=>$username, 'pwd'=>$pwd, "age"=>$age));
//print_r($redis->keys("*"))
header("location:list.php");
?>
=============
list.php
<?php
require('test.php');
$count = $redis->get('userId');
//echo $count;
for ($i=1; $i<=$count; $i++) {
// print_r($redis->hGetAll("user:".$i));
$data[] = $redis->hGetAll("user:".$i);
}
$data = array_filter($data);//过滤掉空数组(删除造成的)
?>
<a href='add.php'>注册</a>
<table border='1'>
<tr>
<th>姓名</th>
<th>密码</th>
<th>年龄</th>
<th>操作</th>
</tr>
<?php
foreach ($data as $v) {
?>
<tr>
<td><?php echo $v['username'];?></td>
<td><?php echo $v['pwd'];?></td>
<td><?php echo $v['age'];?></td>
<td><a href="del.php?id=<?php echo $v['uid']; ?>">删除</a><a href="modify.php?id=<?php echo $v['uid']; ?>">修改</a></td>
</tr>
<?php }
?>
</table>
=========================
del.php
<?php
require('test.php');
$uid = $_REQUEST['id'];
//$uid='10000';
$num = $redis->del("user:".$uid);
//echo $num;exit();
if ($num == 0) {
echo "删除失败";
} else {
header("location:list.php");
}
?>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。