<?php
ini_set('default_socket_timeout', -1);
class Subservice
{
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 psubscribe($patterns = array('__keyevent@0__:expired'), $callback="keyCallback")
{
$this->redis->psubscribe($patterns, $callback);
}
public function setOption()
{
$this->redis->setOption(\Redis::OPT_READ_TIMEOUT, -1);
}
}
?>
<?php
//命令端运行
require_once "Subservice.php";
$Redis = new Subservice(); //实力化类
$Redis->setOption();//设置运行时间
$Redis->psubscribe(['__keyevent@0__:expired'],'shop');//设置运行回调方法
function shop($redis, $pattern, $chan, $msg){
echo $msg; //接收订单ID
}
?>