How to use redis to cancel an order in 15 minutes in thinkphp5?
过去多啦不再A梦2017-06-06 09:52:43
0
5
1704
1. I want to use the queue to detect whether the order has been placed for more than 15 minutes. If it exceeds 15 minutes, modify the database to timeout cancellation, but I don’t know how to start.
This function can be made to trigger user behavior. For example, when the user checks the order and determines that it has not been paid and it has exceeded 15 minutes, the order status will be changed to timeout cancellation. Orders that have not been viewed and whose status has not been updated may be updated in the early morning by scheduled tasks. When the order volume is large, it is not recommended to synchronize the status of all orders in real time, and it is meaningless.
Database polling: Use scheduled tasks to poll the database and query related order processing. Use it when the volume is not large. This method is simple, practical and easy to maintain in small projects
Ring Queue: Reference: http://mp.weixin.qq.com/s/mvF...
Queue service: Use delayed queue processing Reference: http://tech.youzan.com/queuin...
A better solution is to use a time wheel, which is the ring queue mentioned above. It can also be achieved using Redis key space notification. Set the expiration time to 15 minutes, listen for key deletion events, and perform corresponding operations
Plan: Write a PHP script, execute the daemon process, while loop, check the library, if the order takes more than 15 minutes, and the order is unpaid and unshipped, the cancellation operation will be performed
This function can be made to trigger user behavior. For example, when the user checks the order and determines that it has not been paid and it has exceeded 15 minutes, the order status will be changed to timeout cancellation. Orders that have not been viewed and whose status has not been updated may be updated in the early morning by scheduled tasks. When the order volume is large, it is not recommended to synchronize the status of all orders in real time, and it is meaningless.
Database polling: Use scheduled tasks to poll the database and query related order processing. Use it when the volume is not large. This method is simple, practical and easy to maintain in small projects
Ring Queue: Reference: http://mp.weixin.qq.com/s/mvF...
Queue service: Use delayed queue processing Reference: http://tech.youzan.com/queuin...
A better solution is to use a time wheel, which is the ring queue mentioned above.
It can also be achieved using Redis key space notification. Set the expiration time to 15 minutes, listen for key deletion events, and perform corresponding operations
Isn’t it good to use a timer?
No need for redis
You can do it with MySQL
Plan:
Write a PHP script, execute the daemon process,
while loop, check the library, if the order takes more than 15 minutes, and the order is unpaid and unshipped, the cancellation operation will be performed