A simple Queue implementation integrated into easySwoole

2.0.2 2019-10-31 13:52 UTC

This package is auto-updated.

Last update: 2019-12-31 00:30:41 UTC


README

use EasySwoole\Redis\Config\RedisConfig;
use EasySwoole\RedisPool\RedisPool;
use EasySwoole\Queue\Driver\Redis;
use EasySwoole\Queue\Queue;
use EasySwoole\Queue\Job;

$config = new RedisConfig([
    'host'=>'127.0.0.1'
]);
$redis = new RedisPool($config);

$driver = new Redis($redis);
$queue = new Queue($driver);

go(function ()use($queue){
    while (1){
        $job = new Job();
        $job->setJobData(time());
        $id = $queue->producer()->push($job);
        var_dump('job create for Id :'.$id);
        \co::sleep(3);
    }
});

go(function ()use($queue){
    $queue->consumer()->listen(function (Job $job){
        var_dump($job->toArray());
    });
});