Php + redis how to design a timed release function

Source: Internet
Author: User
Now I want to implement the function of publishing a regular article. How can I design the Article id and release time in redis? During the release time, I change the article status to release? Now you want to implement the function of publishing articles regularly, and put the Article id and release time in redis.

How can I design and change the article status to publish at the release time?

Reply content:

Now you want to implement the function of publishing articles regularly, and put the Article id and release time in redis.

How can I design and change the article status to publish at the release time?

Cron writes a command to regularly execute scripts.Array_shift ()Output the first article array, run the command to send this id article, and storeShiftAfter the array to redis, if it fails, add it back.

If it is to record the release time, useArray_filterFilter the time. The default time is 0 or other values. If the time constant is equal to the default time, the default time is true. Then obtain the id of the first article to publish the article. If it succeeds, the time is recorded. If it fails, the time is not changed and the article array is stored in redis.

Use crontab to run a PHP script every minute. This script is used to query whether there are any articles to be published. If so, it is published and changed to published. This is a simple idea.

The status is set to the prerelease status. When querying an article, filter the release time to the future time. The prerelease status + release time can determine that the article is published. If you must set the release status value, you can judge and update after the query. If you need to "Schedule", use cron.

Another idea is to set the status of the article to published, and then the redis storage Article id, and set the expiration time to the release timestamp minus the current timestamp, to query an article, filter the Article id in redis so that the article will come out at the release time. However, to query this article, you need to encapsulate it.

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.