本文实例讲述了redis+php实现微博列表功能。分享给大家供大家参考,具体如下:
个人主页显示微博列表(自己及关注人的微博列表)
/*获取最新的50微博信息列表,列出自己发布的微博及我关注用户的微博 *1.根据推送的信息获取postid *2.根据postid获取发送的信息 */ $r->ltrim("recivepost:".$user['userid'],0,49); $postid_arr = $r->sort("recivepost:".$user['userid'],array('sort'=>'desc')); if($postid_arr){ foreach($postid_arr as $postid){ $p = $r->hmget("post:postid:".$postid,array('userid','username','time','content')); $weiboList .= '<div class="post"><a class="username" href="profile.php?u='.$p['username'].'" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >'.$p['username'].'</a>'.$p['content'].'<br><i>'.formattime($p['time']).'前发布</i></div>'; } echo $weiboList; }else{ echo '<div class="post" >这个家伙很懒,还未发布消息哦~</div>'; }
显示个人微博列表
/** *1.获取个人发布微博的id的队列 *2.根据postid获取微博信息 **/ $r->ltrim("userpostid:".$prouid,0,49); $postid_arr = $r->sort("userpostid:".$prouid,array('sort'=>'desc')); if($postid_arr){ foreach($postid_arr as $postid){ $p = $r->hmget("post:postid:".$postid,array('userid','username','time','content')); $weiboList .= '<div class="post"><a class="username" href="profile.php?u='.$p['username'].'" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >'.$p['username'].'</a>'.$p['content'].'<br><i>'.formattime($p['time']).'前发布</i></div>'; } echo $weiboList; }else{ echo '<div class="post" >这个家伙很懒,还未发布消息哦~</div>'; }
更多关于PHP相关内容感兴趣的读者可查看本站专题