How to realize automatic cancellation of order timeout by Python
Python how to achieve automatic cancellation of order timeout, for this problem, this article details the corresponding analysis and answer, hoping to help more small partners who want to solve this problem to find a simpler and easier way.
Business scenario: After the user places an order, if the payment is not completed within the specified time, the order is automatically cancelled and the inventory is released. Technology: Redis key space notification (expiration callback) After the user places an order, the order id is stored as a key and any value is stored as a value in redis. The expiration time is set for this data, that is, the time when the order expires. Enable key space notification.
Keyspace event notification is disabled by default. We can enable them in redis.conf or redis-cli (windows in redis.window-server.conf) as follows:
Or use the command line settings:
redis-cli config set notify-keyspace-events Ex
Parameter Description:
Here we only monitor expiration events, so Ex is set
Test effect:
$ redis-cli --csv psubscribe '*'
Reading messages... (press Ctrl-C to quit)
"psubscribe","*",1
psubscribe '*' means we want to subscribe to all events using schema *
Open a new terminal connection redis
Application in Python
The callback function can cancel the order and restore the inventory only by getting the expired order_id
About Python how to achieve automatic cancellation of orders timeout answer to share here, I hope the above content can have some help for everyone, if you still have a lot of doubts not solved, you can pay attention to the industry information channel to learn more related knowledge.