SNS好友的redis结构设计

Redis的性能总结:

Results: about 110000 SETs per second, about 81000 GETs per second

(摘录自百度百科)

依据这个结果, 中小型项目中, 好友发送请求和接受请求,无需其它消息队列辅助, redislist结构建消息队列可以很好的满足需求。

用户信息

采用redishash数据结构

Key            user:$uid

Value        uid=>$uid, uname=>$username, friend=>$freindnum, $hidefriend=>$hidefriendnum

备注:

$uid 用户UID

$username 用户名

$friendnum 用户好友数

$hidefriendnum 用户隐藏的好友数(有些项目可能不需要隐藏好友)

例:

user:10001

uid=>10001, uname=>allen1, friend=>100, $hidefriend=>10

user:10002

uid=>10002, uname=>allen2, $hidefriend=>10

用户发送的好友请求

采用redislist数据类型

Key            friend:request:$uid

Value        $uid

备注:

$uid 用户UID

friend:request:10001 friend:request:10002
index value index value
0 10002 0 10003
1 10003 1 10004
2 10004 2 10005
3 10005 3 10006
4 10006 4 10007

用户接收好友请求

采用redis的list数据类型

Key            friend:response:$uid

Value        $uid

备注:

$uid 用户UID

friend:response:100001 friend:response:100002
index value index value
0 100012 0 10013
1 100013 1 10014
2 100014 2 10015
3 100015 3 10016
4 100016 4 10017

用户的好友

采用rediszset数据类型

Key            friend:$uid

Value        $score  $uid

备注:

$uid 用户UID

friend:10001 friend:10002
score value score value
1333704370 10012 1333704370 10013
1333704371 10013 1333704371 10014
1333704372 10014 1333704372 10015
1333704373 10015 1333704373 10016
1333704374 10016 1333704374 10017

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值