In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
How to use Redis to implement a delayed task in PHP? aiming at this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.
(a) Business scenarios:
1. When a business is triggered, you need to start a scheduled task and perform another task within a specified time (such as automatic cancellation of orders, automatic completion of orders, etc.)
2. The keyspace notifications of redis sends an event after the key expires, and the client listening for this event can receive a notification.
(B) Service preparation:
1. Modify the reids configuration file (redis.conf) [window system configuration file is: redis.windows.conf]
Redis does not enable keyspace notifications by default, because it consumes cpu when enabled.
Note: E:keyevent event, which is published with the prefix _ _ keyevent@__
X: expiration event, which occurs when a key expires and is deleted
The original configuration was:
Notify-keyspace-events ""
Change the configuration as follows:
Notify-keyspace-events "Ex"
After saving the configuration, restart the Redis service to make the configuration effective
[root@chokingwin etc] # service redis-server restart / usr/local/redis/etc/redis.conf Stopping redis-server: [OK] Starting redis-server: [OK]
Restart redis on the window system, first change to the redis file directory, then turn off the redis service (redis-server-- service-stop), and then turn on (redis-server-- service-start)
(C) document code:
Phpredis implements subscription Keyspace notification, which can cancel the order automatically and complete the order automatically. The following is a test example
Create 4 files, and then modify the database and redis configuration parameters
Db.class.php
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.