Phpredis-how to implement PHP-redis like Weibo subscription service

Source: Internet
Author: User
This is the requirement. Anyone who has ever played Weibo knows the following features. Many people can send Weibo posts. When I log on to Weibo again some time later, the latest Weibo posts from people I followed will be displayed in chronological order. How can I use php and redis to implement such a subscription... this is the requirement. Anyone who has played Weibo knows the following features:

  1. Many people
  2. Everyone can send Weibo posts.
  3. When I log on to Weibo again after a while, the latest Weibo posts will be displayed in chronological order.

How can I use php and redis to implement such a subscription? I hope you can give me some ideas or references.

(Do not give specific answers, but try to make them as detailed as possible)

Reply content:

This is the requirement. Anyone who has played Weibo knows the following features:

  1. Many people
  2. Everyone can send Weibo posts.
  3. When I log on to Weibo again after a while, the latest Weibo posts will be displayed in chronological order.

How can I use php and redis to implement such a subscription? I hope you can give me some ideas or references.

(Do not give specific answers, but try to make them as detailed as possible)

In fact, this is a great and complex system. I will talk about my ideas. If you want to know the Weibo posts you are interested in, there are two ways: push and pull.

The pushing method is that every Weibo user will push his Weibo ID to all of his fans. It is clear that Fan Ye is a big fan and will die.

The pull method is that each person takes the initiative to pull all the latest Weibo posts of the people they are interested in. If there are too many followers, it is not feasible.

In general, push and pull should be combined. It is hard to say how to combine them. Each user will have his own list to store unread Weibo IDs, and then continue to push and pull, whether it is the push-pull process, the Services behind it are certainly being processed, not real-time.

Obtaining Weibo is not a batch query of SQL statements. It is all atomic operations. For example, if there are 100 unread Weibo posts, they will be retrieved from the cache 100 times in a loop, you can also use redis mutil for batch retrieval. If you do not read it, it will be retrieved from the source database. This may be slow, but it is not slow in actual use because a large number of caches are used.

Sina has shared their queue system architecture several times. We suggest you look for infoq.
There is no way to give you a detailed summary here, but the general ideas are already shared.
We mainly use collections and linked lists, plus the pull and pull mentioned above. Very complicated, really.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.