Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to realize automatic cancellation of order timeout by Python

Shulou Source: shulou.com Published: 2022-06-01 11:22:31 09月26日 Update

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.

Tags: Orders events time space questions inventory more users help answers easy easy business that is content functions functions parameters just commands Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Shulou Information vpn Shulou Technology MariaDB