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");
redis+php实现微博功能(二)的更多相关文章
- redis+php实现微博功能(一)
(一).微博功能概况 微博用户账号注册 微博用户登录 微博发布 添加微博好友(粉丝) 微博推送 微博冷数据写入mysql数据库 (二).redis数据结构设计 这节分享微博用户注册与登录:我们完全采用 ...
- redis+php实现微博功能(三)
个人主页显示微博列表(自己及关注人的微博列表) /*获取最新的50微博信息列表,列出自己发布的微博及我关注用户的微博 *1.根据推送的信息获取postid *2.根据postid获取发送的信息 */ ...
- redis成长之路——(二)
redis操作封装 针对这些常用结构,StackExchange.Redis已经做了一些封装,不过在实际应用场景中还必须添加一些功能,例如重试等 所以对一些常功能做了一些自行封装SERedisOper ...
- 开启SharePoint Server 2013 中的“微博”功能——新闻源
熟悉SharePoint的朋友在2013之前的版本可以使用社区协作下的记事板.应用程序下的通知,来进行消息的发布,而且更有这两者的完美结合体讨论板,可供使用着根据站点属性进行添加而对现在的快消息时代, ...
- Redis Geo: Redis新增位置查询功能
转载于:http://www.itxuexiwang.com/a/shujukujishu/redis/2016/0216/144.html 移动互联网增进了人与人之间的联系,其中基于位置信息的服务( ...
- 转:Redis Geo: Redis新增位置查询功能
原文来自于:http://www.infoq.com/cn/news/2015/07/redis-geo 移动互联网增进了人与人之间的联系,其中基于位置信息的服务(Location Based Ser ...
- Redis实现世界杯排行榜功能(实战)
转载请注明出处:https://www.cnblogs.com/wenjunwei/p/9754346.html 需求 前段时间,做了一个世界杯竞猜积分排行榜.对世界杯64场球赛胜负平进行猜测,猜对+ ...
- Redis源码阅读(二)高可用设计——复制
Redis源码阅读(二)高可用设计-复制 复制的概念:Redis的复制简单理解就是一个Redis服务器从另一台Redis服务器复制所有的Redis数据库数据,能保持两台Redis服务器的数据库数据一致 ...
- Redis指令与数据结构(二)
0.Redis目录结构 1)Redis介绍及部署在CentOS7上(一) 2)Redis指令与数据结构(二) 3)Redis客户端连接以及持久化数据(三) 4)Redis高可用之主从复制实践(四) 5 ...
随机推荐
- angularJS---初识指令
angularJS 什么是angularJS AngularJS 诞生于2009年,由Misko Hevery 等人创建,后为Google所收购.是一款优秀的前端JS框架,已经被用于Google的多款 ...
- OLT配置说明
MA5680T>enable 进入特权模式 MA5680T#config 进入配置模式 MA5680T(config)#display current-configuration sim ...
- procrdure存储过程
/* 存储过程 在一些语言中,有一个概念叫”过程“ procedure,和”函数“ function 过程:封装了若干条语句,调用时,这些封装体执行 函数:是一个有返回值的“过程” 过程:没有返回值的 ...
- New Concept English there (6)
30w/m The expensive shops in a famous arcade near Piccadilly were just opening. At this time of the ...
- Struts2开发步骤
第一步:新建we项目 新建名称为“Struts"的web工程,新建方法:File->New->Web Service Project->Profect Name中输入:St ...
- (转)Mahout Kmeans Clustering 学习
一.Mahout命令使用 合成控制的数据集 synthetic_control.data 可以从 此处下载,总共由600行X60列double型的数据组成, 意思是有600个元组,每个元组是一个时间序 ...
- android 几个开源项目
android的几个开源项目ormlite.volley.jsoup.vitamio ksoap2
- 【剑指offer】顺时针打印矩阵,C++实现
原创文章,转载请注明出处! 博客文章索引地址 1.题目 输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字,例如,如果输入如下矩阵,则依次打印出数字1,2,3,4,8,12,16,15,14 ...
- Win10 Backup&Restore Start Menu(备份还原开始菜单)
Win10 的开始菜单,不是很稳定!系统装完4天,开始乱了3次,要知道我的开始菜单全屏并且进过尽心布局的,很是心酸! 连着找了几天备份开始菜单的方法,无果!后来发现了下边两个PowerShell命令, ...
- C/C++比较容易搞混的一些写法
#include <stdio.h> int main() { int a = 101; char ch = *(char *)&a; //*(char *)&a:含义就是 ...