婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > redis+php實現微博(二)發布與關注功能詳解

redis+php實現微博(二)發布與關注功能詳解

熱門標簽:智能電話機器人好公司門薩維 聊城電話外呼系統公司 德陽中江如何申請400開頭電話 AI電話機器人OEM貼牌 沛縣400電話辦理 江蘇電商外呼系統運營商 青白江地圖標注 銅川電話機器人價格 辦理重慶400電話

本文實例講述了redis+php實現微博發布與關注功能。分享給大家供大家參考,具體如下:

數據結構:

set post:postid:3:time timestamp
set post:postid:3:userid 5
set post:postid:3:content 測試發布哈哈哈哈

incr global:postid
set post:postid:$postidcho "用戶名密碼不能夠為空!";

關注微博

following:3

被關注(粉絲)

followed:3

把發布的微博推給自己的粉絲

recivepost:10 postid

微博的發布代碼:

include("function.php");
include("header.php");
$content = I('content');
if(!$content){
  error('內容不能夠為空');
}
$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);
}
//單獨累計個人發布的信息
$r->lpush('userpostid:'.$user['userid'],$postid);
header("location:home.php");
exit;
include("bottom.php");

微博的關注代碼:

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){
  //將關注與被關注的數據結構存入redis
  $r->sadd("following:".$user['userid'],$uid);
  $r->sadd("followed:".$uid,$user['userid']);
}else{ 
  //取消關注
  $r->srem("following:".$user['userid'],$uid);
  $r->srem("followed:".$uid,$user['userid']);
}
//根據傳遞過來的userid查找username
$uname = $r->get("user:userid:".$uid.":username");
header("location:profile.php?u=".$uname);
include("bottom.php");

更多關于PHP相關內容感興趣的讀者可查看本站專題:《php+redis數據庫程序設計技巧總結》、《php面向對象程序設計入門教程》、《PHP基本語法入門教程》、《PHP數組(Array)操作技巧大全》、《php字符串(string)用法總結》、《php+mysql數據庫操作入門教程》及《php常見數據庫操作技巧匯總》

希望本文所述對大家PHP程序設計有所幫助。

您可能感興趣的文章:
  • PHP實現發送微博消息功能完整示例
  • redis+php實現微博(三)微博列表功能詳解
  • redis+php實現微博(一)注冊與登錄功能詳解
  • PHP+redis實現微博的拉模型案例詳解
  • PHP+redis實現微博的推模型案例分析
  • vue+php實現的微博留言功能示例
  • php微信分享到朋友圈、QQ、朋友、微博
  • PHP調用微博接口實現微博登錄的方法示例
  • php新浪微博登錄接口用法實例
  • 基于PHP實現發微博動態代碼實例

標簽:烏魯木齊 山南 南寧 迪慶 濟寧 三亞 赤峰 鷹潭

巨人網絡通訊聲明:本文標題《redis+php實現微博(二)發布與關注功能詳解》,本文關鍵詞  redis+php,實現,微博,二,發布,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《redis+php實現微博(二)發布與關注功能詳解》相關的同類信息!
  • 本頁收集關于redis+php實現微博(二)發布與關注功能詳解的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 凤山县| 淮滨县| 黑龙江省| 大庆市| 沧源| 巨野县| 砚山县| 永仁县| 贞丰县| 利辛县| 海安县| 定日县| 仙居县| 呼伦贝尔市| 靖州| 宁德市| 新巴尔虎左旗| 蓬溪县| 鄂温| 海兴县| 福清市| 西盟| 汶川县| 宁陕县| 喜德县| 龙南县| 招远市| 南华县| 栾川县| 阜新市| 含山县| 连南| 奉新县| 广宁县| 平谷区| 阳原县| 正镶白旗| 盖州市| 丰都县| 桐城市| 灵武市|