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 storeShift
After the array to redis, if it fails, add it back.
If it is to record the release time, useArray_filter
Filter 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.