PHP code example of mix / delayer-client

1. Go to this page and download the library: Download mix/delayer-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mix / delayer-client example snippets



�与Delayer服务器端配置的redis信息相同
$config  = [
    'host'     => '127.0.0.1',
    'port'     => 6379,
    'database' => 0,
    'password' => '',
];
$client  = new \Delayer\Client($config);
// 任务数据,用户自己定义
$data    = [
    'orderID' => '2018101712578956648885474',
    'action'  => 'close',
];
$message = new \Delayer\Message([
    // 任务ID,必须全局唯一
    'id'    => md5(uniqid(mt_rand(), true)),
    // 主题,取出任务时需使用
    'topic' => 'close_order',
    // 必须转换为string类型
    'body'  => json_encode($data),
]);
// 第2个参数为延迟时间,第3个参数为延迟到期后如果任务没有被消费的最大生存时间
$ret     = $client->push($message, 20, 604800);
var_dump($ret);


�与Delayer服务器端配置的redis信息相同
$config  = [
    'host'     => '127.0.0.1',
    'port'     => 6379,
    'database' => 0,
    'password' => '',
];
$client  = new \Delayer\Client($config);
$message = $client->pop('close_order');
// 没有任务时,返回false
var_dump($message);
var_dump($message->body);


�与Delayer服务器端配置的redis信息相同
$config  = [
    'host'     => '127.0.0.1',
    'port'     => 6379,
    'database' => 0,
    'password' => '',
];
$client  = new \Delayer\Client($config);
$message = $client->bPop('close_order', 10);
// 没有任务时,返回false
var_dump($message);
var_dump($message->body);


�与Delayer服务器端配置的redis信息相同
$config = [
    'host'     => '127.0.0.1',
    'port'     => 6379,
    'database' => 0,
    'password' => '',
];
$client = new \Delayer\Client($config);
// push时定义的任务ID
$id = '***';
$ret    = $client->remove($id);
var_dump($ret);