因为刚开发完成时间不长,目前还处于内测中,基本功能已通过测试。
使用composer安装:
<?php
require_once './vendor/autoload.php';
$redisConfig = [
'host' => '127.0.0.1',
'port' => '6379',
'database' => '0',
'password' => '',
'timeout' => 60
];
<?php
require_once 'public.php';
$redis = (new \Soen\Delay\Alone\Redis($redisConfig))->getDriver();
$deplayer = new \Soen\Delay\Alone\Polling(1, $redis);
$deplayer->run();
执行php index.php
,会运行延迟队列的服务端,扫描到期的数据并移到延迟队列
<?php
require_once 'public.php';
$redis = (new \Soen\Delay\Alone\Redis($redisConfig))->getDriver();
$client = new \Soen\Delay\Alone\Client\Client($redis);
//生成随机数 body 数据
$strs="QWERTYUIOPASDFGHJKLZXCVBNM1234567890qwertyuiopasdfghjklzxcvbnm";
$name=substr(str_shuffle($strs),mt_rand(0,strlen($strs)-11),10);
/**
* 随机生成ID,固定topic1, 随机body数据,延迟队列延迟10秒更新
*/
$has = $client->push(rand(1,999),'topic1',['a'=>$name,'b'=>$name],10);
if($has){
echo '数据提交成功'.PHP_EOL;
}else {
echo '提交失败'.PHP_EOL;
}
cli内执行 php push.php
, 就会提交一组等待处理的数据
<?php
require_once 'public.php';
$redis = (new \Soen\Delay\Alone\Redis($redisConfig))->getDriver();
$client = new Soen\Delay\Alone\Client\Client($redis);
$data = $client->bPop('topic1');
var_dump($data);
cli执行php pop.php
,进行队列消费