用户信息
采用redis的hash数据结构
Key user:$uid
Value uid=>$uid,uname=>$username, follower=>$followernum, following=>$followingnum
备注:
$uid 用户UID
$username 用户名
$followernum 用户的粉丝数
$followingnum 用户关注数
例:
user:10001
uid=>10001, uname=>allen1,follower=>100, following=>100, friend=>100, hidefollowing=>10,$hidefriend=>10
user:10002
uid=>10002, uname=>allen2,follower=>100, following=>100, friend=>100, hidefollowing=>10,$hidefriend=>10
…
粉丝
采用redis的zset数据类型
Key follower:$uid
Value $score $uid
备注:
$uid 用户UID
$score 时间戳
例
follower:10001
score value
1333598050 10002
1333598051 10003
1333598052 10004
1333598053 10005
1333598054 10006
…
follower:10002
score value
1333598060 10001
1333598061 10003
1333598062 10007
1333598063 10008
1333598064 10009
在这个基础上,可以实现如下需求:
1 获取用户10001或用户10002的粉丝
2 获取与用户10001相互关注的用户
2 判断用户10001和用户10002是否相互关注
4 判断用户10001是否是用户10002的粉丝
…