本文实例讲述了redis+php实现微博发布与关注功能。分享给大家供大家参考,具体如下:
数据结构:
t post:postid:3:time timestamp
t post:postid:3:urid 5
t post:postid:3:content 测试发布哈哈哈哈incr global:postid
t post:postid:$postidcho “用户名密码不能够为空!”;
关注微博
following:3
被关注(粉丝)
followed:3
把发布的微博推给自己的粉丝
recivepost:10 postid
微博的发布代码:
include("function.php");include("header.php");$content = i('content');if(!$content){ error('内容不能够为空');}$ur = islogin();if($ur==fal){ header("location:index.php"); exit();}$r = redis_connect();$postid = $r->incr('global:postid');//$r->t("post:postid:".$postid.":time",time());//$r->t("post:postid:".$po曹衣带水stid.":urid",$ur['urid']);//$r->t("post:postid:".$postid.":content",$c高中化学必背基础知识ontent);$r->hmt("post:postid:".$postid,array('urid'=>$ur['urid'],'urname'=>$ur['urname'],'time'=>time(),'content'=>$content));//把微博推给自己的粉丝$fans = $r->smembers("followed:".$ur['urid']);$fans[] = $ur['urid'];foreach($fans as $fansid){ $r->lpush('recivepost:'.$fansid,$postid);}//单独累计个人发布的信息$r->lpush('urpostid:'.$ur['urid'],$postid);header("location:home.php");exit;include("bottom.php");
微博的关注代码:
include("function.php");include("header.php");if(islogin()==fal){ header("location:index.php"); e婴儿脑积水xit;}$ur = islogin();$uid = trim($_get['uid']);$f = trim($_get['f']);$r = redis_connect();if($f==0){ //将关注与被关注的数据结构存入redis $r->sadd("following:".$ur['urid'],$uid); $r->sadd("followed:".$uid,$ur['urid']);}el{ //取消关注 $r->srem("following:".$ur['urid'],$uid); $r->srem("followed:".$uid,$ur['urid']);}//根据传递过来的urid查找urname$uname = $r->get(manager是什么意思"ur:urid:".$uid.":urname")专业分数线;header("location:profile.php?u=".$uname);include("bottom.php");
本文发布于:2023-04-08 07:17:20,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/c562dd69a2cc414fe398dfe7f9579254.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:redis+php实现微博(二)发布与关注功能详解.doc
本文 PDF 下载地址:redis+php实现微博(二)发布与关注功能详解.pdf
留言与评论(共有 0 条评论) |