今天看了一个老视频:http://v.youku.com/v_show/id_XMzM3NjgzMjY4.html
里面说到这个问题“A关注了B,B也关注A,要得到两个人的共同好友,好友取交集。如果A是一个粉丝有3000万的大V,而B是粉丝只有1000的屌丝,要找出他们的共同好友,应该怎么做?”
视频看完了,我却米有找到答案。大家帮忙分析下。
首先得是redis,第二,得合理,不能用户查看的时候等待个四五秒。
大家讲道理2017-04-21 11:18:41
This calculation process is not a one-time http operation, and it cannot be calculated immediately unless you are a very experienced algorithm engineer and data engineer.
These things are calculated slowly in the background. Otherwise, what do the data mining engineers rely on? When the calculated results are calculated, they will start pushing them to you. At this time, the benefits of using static language and resident memory on the server side can be reflected.
伊谢尔伦2017-04-21 11:18:41
After watching the video, it was clearly stated: pre-calculation. (Watch from 10 minutes and 30 seconds)
Just calculate it when you pay attention (inserting data).
巴扎黑2017-04-21 11:18:41
It’s easy to use redis sets.
Example:
user:1:fans [2,3,4] //Follow users 1
user:1:follows [2,5,7,8] //User 1 follows
user:2:fans [1,3,4] //Follow users 2
user:2:follows [1,7,8] //User 2 follows
When user 1 logs in, he can get the friend relationship by taking the intersection of user:1:fans and user:1:follow. Then, can he get the intersection by taking the intersection of user:1:follows and user:2:follows? Users you follow in common? I believe I don’t need to explain the rest of the intersection differences, you should know it too