欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

redis+php實(shí)現(xiàn)微博(二)發(fā)布與關(guān)注功能詳解

 更新時(shí)間:2019年09月23日 10:11:29   作者:巴八靈  
這篇文章主要介紹了redis+php實(shí)現(xiàn)微博發(fā)布與關(guān)注功能,結(jié)合實(shí)例形式分析了php結(jié)合redis實(shí)現(xiàn)微博的發(fā)布及關(guān)注相關(guān)操作技巧,需要的朋友可以參考下

本文實(shí)例講述了redis+php實(shí)現(xiàn)微博發(fā)布與關(guān)注功能。分享給大家供大家參考,具體如下:

數(shù)據(jù)結(jié)構(gòu):

set post:postid:3:time timestamp
set post:postid:3:userid 5
set post:postid:3:content 測試發(fā)布哈哈哈哈

incr global:postid
set post:postid:$postidcho "用戶名密碼不能夠?yàn)榭?";

關(guān)注微博

following:3

被關(guān)注(粉絲)

followed:3

把發(fā)布的微博推給自己的粉絲

recivepost:10 postid

微博的發(fā)布代碼:

include("function.php");
include("header.php");
$content = I('content');
if(!$content){
  error('內(nèi)容不能夠?yàn)榭?);
}
$user = isLogin();
if($user==false){
  header("location:index.php");
  exit();
}
$r = redis_connect();
$postid = $r->incr('global:postid');
//$r->set("post:postid:".$postid.":time",time());
//$r->set("post:postid:".$postid.":userid",$user['userid']);
//$r->set("post:postid:".$postid.":content",$content);
$r->hmset("post:postid:".$postid,array('userid'=>$user['userid'],'username'=>$user['username'],'time'=>time(),'content'=>$content));
//把微博推給自己的粉絲
$fans = $r->smembers("followed:".$user['userid']);
$fans[] = $user['userid'];
foreach($fans as $fansid){
  $r->lpush('recivepost:'.$fansid,$postid);
}
//單獨(dú)累計(jì)個(gè)人發(fā)布的信息
$r->lpush('userpostid:'.$user['userid'],$postid);
header("location:home.php");
exit;
include("bottom.php");

微博的關(guān)注代碼:

include("function.php");
include("header.php");
if(isLogin()==false){
  header("location:index.php");
  exit;
}
$user = isLogin();
$uid = trim($_GET['uid']);
$f = trim($_GET['f']);
$r = redis_connect();
if($f==0){
  //將關(guān)注與被關(guān)注的數(shù)據(jù)結(jié)構(gòu)存入redis
  $r->sadd("following:".$user['userid'],$uid);
  $r->sadd("followed:".$uid,$user['userid']);
}else{ 
  //取消關(guān)注
  $r->srem("following:".$user['userid'],$uid);
  $r->srem("followed:".$uid,$user['userid']);
}
//根據(jù)傳遞過來的userid查找username
$uname = $r->get("user:userid:".$uid.":username");
header("location:profile.php?u=".$uname);
include("bottom.php");

更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php+redis數(shù)據(jù)庫程序設(shè)計(jì)技巧總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《PHP基本語法入門教程》、《PHP數(shù)組(Array)操作技巧大全》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總

希望本文所述對大家PHP程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評論