In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
What this article shares with you is what is the callback event triggered by the failure of php snooping redis key. The editor thinks it is very practical, so I share it with you. I hope you can learn something after reading this article. Let's take a look at it with the editor.
Solution to order timeout and activity expiration: php snooping redis key failure triggers callback events
Redis version 2.8.0 is available, key space message (Redis Keyspace Notifications), with version 2.0.0 after the SUBSCRIBE can complete the operation of this scheduled task, the timing unit is seconds.
1. Let's subscribe to the channel named redisChat first.
two。 Now, let's reopen a redis client, then post the message on the same channel redisChat, and the subscriber can receive the message.
The message received is as follows:
Redis configuration for 3.Key expiration events
Here you need to configure the parameter "Ex" for notify-keyspace-events. X represents an expired event. After notify-keyspace-events "Ex" saves the configuration, restart the Redis service to make the configuration take effect.
PHP redis implements subscription key space notification
The redis instantiation class:
Redis.class.php
/ / Redis2class Redis2 {private $redis; public function _ construct ($host = '127.0.0.1, $port = 6379) {$this- > redis = new Redis (); $this- > redis- > connect ($host, $port);} public function setex ($key, $time, $val) {return $this- > redis- > setex ($key, $time, $val) } public function set ($key, $val) {return $this- > redis- > set ($key, $val);} public function get ($key) {return $this- > redis- > get ($key);} public function expire ($key = null, $time = 0) {return $this- > redis- > expire ($key, $time);} public function psubscribe ($patterns = array (), $callback) {$this- > redis- > psubscribe ($patterns, $callback) } public function setOption () {$this- > redis- > setOption (\ Redis::OPT_READ_TIMEOUT,-1);}}
Subscriptions to expired events:
Psubscribe.php
Require_once'. / Redis.class.php';$redis = new\ Redis2 (); / / solve the Redis client subscription timeout $redis- > setOption (); $redis- > psubscribe (array ('_ keyevent@0__:expired'), 'keyCallback'); / / callback function, where the processing logic function keyCallback ($redis, $pattern, $chan, $msg) {echo "Pattern: $pattern\ n"; echo "Channel: $chan\ n" Echo "Payl oad: $msg\ n\ n"; / / keyCallback is the callback function after the subscription event. The business processing logic is written here. / / for example, if the goods mentioned above are automatically withdrawn without payment, you can automatically withdraw orders according to the order id.
Set expiration events:
Index.php
Require_once'. / Redis.class.php';$redis = new\ Redis2 (); $order_id = 123 leading events-> setex ('order_id',10,$order_id)
Execute psubscribe.php in command line mode first
Access index.php in a browser
This is what the callback event triggered by the failure of php snooping redis key is. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
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.