public function article(){
$article_id=I('id');
$redis=$this->getRedis();
if(IS_POST)
{
$content=I('content');
$time=time();
$comment=(object) null;
$comment->content=$content;
$comment->time=$time;
$c1=json_encode($comment);
if ($redis->exists('listC'))
{
//加入队列
$redis->rpush('listC',$c1);
//dump($redis->lrange('listC',0,-1));
}
else{
//初始化一个sort set
$redis->rpush('listC',$c1);
}
dump($c1);
}
//list_id
$comments= $redis->lrange('listC',-3,-1);
$cos=array();
foreach ($comments as $key=> $value)
{
$cos[$key]['content']=json_decode($value)->content;
$cos[$key]['time']=json_decode($value)->time;
}
dump($cos);
arsort($cos);
if (!$article_id)
{
$article_id=1;
}
$mysqli=new \mysqli('localhost','root','root','ad');
if ($mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}
$sql='select * from article where id ='.$article_id;
$rs= $mysqli->query($sql);
$info=$rs->fetch_all();
dump($cos);
$this->assign('info',$info[0]);
$this->assign('comment',$cos);
$this->display();
}
redis文章评论
最新推荐文章于 2024-03-09 07:00:00 发布