Redis的性能总结:
Results: about 110000 SETs per second, about 81000 GETs per second
(摘录自百度百科)
依据这个结果, 中小型项目中, 好友发送请求和接受请求,无需其它消息队列辅助, redis的list结构建消息队列可以很好的满足需求。
用户信息
采用redis的hash数据结构
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
…
用户发送的好友请求
采用redis的list数据类型
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 |
… | … |
用户的好友
采用redis的zset数据类型
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 |
… | … |