微博项目的key设计

全局相关的key:

表名

global

列名

操作

备注

Global:userid

incr

产生全局的userid

Global:postid

Incr

产生全局的postid

 

 

用户相关的key()

表名

user

Userid

Username

Password

Authsecret

3

Test3

1111111

#U*Q(%_

 

redis,变成以下几个key

Key前缀

user

User:Userid:*

User:userid:*Username

User:userid:*Password

User:userid:*:Authsecret

User:userid:3

User:userid:3:Test3

User:userid:3:1111111

User:userid:3:#U*Q(%_

 

 

微博相关的表设计

表名

post




Postid

Userid

Username

Time

Content

4

2

Lisi

1370987654f

测试内容

 

微博在redis,与表设计对应的key设计

Key前缀

post




Post:Postid:*

Post:postid:*Userid

Post:postid:*:Username

Post:postid:*:Time

Post:postid:*:Content

4

2

Lisi

1370987654f

测试内容

 


image.png关注表: following

Following:$userid -->

 

粉丝表

Follower:$userid ---> image.png

 

推送表:revicepost

image.png

 

=================拉模型,改进=====================

 

拉取表

 

 

image.png


: 上次我拉取了 A->5,67,三条微博, 下次刷新home.php, >7的微博开始拉取

解决: 拉取时,设定一个lastpull时间点, 下次拉取时,>lastpull的微博

 

: 有很多关注人,如何取?

解决: 循环自己的关注列表,逐个取他们的新微博

 

: 取出来之后放在哪儿?

: pull:$userid的链接里

 

: 如果个人中心,只有前1000

: ltrim,只取前1000

 

 

: 如果我关注 A,B两人, 2人中,各取3条最新信息

,3+3条信息, 从时间上,是交错的, 如何按时间排序?

: 我们发布时, 是发布的hash结构, 不能按时间来排序.

 

解决:  同步时,取微博后,记录本次取的微博的最大id,

下次同步时,只取比最大id更大的微博


猜你喜欢

转载自blog.51cto.com/5660061/2366207