Orzzzz
V2EX  ›  问与答

如何存储知乎的关注关系?

  •  
  •   Orzzzz · Oct 8, 2016 · 2401 views
    This topic created in 3548 days ago, the information mentioned may be changed or developed.

    每个用户都有关注者和被关注者,如何存储这种关系,用什么数据库?

    每个话题的关注者,每个用户关注了那些话题,这些数据又该如何存储?

    有哪位前辈指导一下?

    谢谢。

    4 replies    2016-10-09 10:49:45 +08:00
    billlee
        1
    billlee  
       Oct 8, 2016   ❤️ 1
    图数据库
    Neo4j, FlockDB, ...
    用 RDBMS 的多对多关系存储也是可以的
    当然,用 NoSQL, 自己保证一致性也是可以的
    siteshen
        2
    siteshen  
       Oct 9, 2016   ❤️ 1
    -- 用户关注
    -- user_followships: from_user_id, to_user_id
    select to_user_id from user_followships where from_user_id = '1024'; -- 列出“用户 1024 ”关注的 user_id
    select from_user_id from user_followships where to_user_id = '1024'; -- 列出关注“用户 1024 ”的 user_id

    -- 话题关注:参考用户关注
    siteshen
        3
    siteshen  
       Oct 9, 2016   ❤️ 1
    -- 补充下:关注 /取消关注的 sql
    insert into user_followships values(1024, 2048); -- “用户 1024 ”关注“用户 2048 ”
    delete from user_followships where from_user_id=1024 and to_user_id=2048; -- “用户 1024 ”取消关注“用户 2048 ”
    misaka19000
        4
    misaka19000  
       Oct 9, 2016
    <_id><被关注者 id><关注着 id>
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1042 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 23:20 · PVG 07:20 · LAX 16:20 · JFK 19:20
    ♥ Do have faith in what you're doing.