Giter Club home page Giter Club logo

delayer-client-php's Introduction

Delayer PHP 客户端

客户端使用非常简单,提供了 pushpopbPopremove 四个方法操作任务。

安装

通过 Composer 安装使用:

composer require mix/delayer-client

Example

push 方法

放入一个任务。

<?php
include '../vendor/autoload.php';
// 要与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);

pop 方法

取出一个到期的任务。

<?php
include '../vendor/autoload.php';
// 要与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);

bPop 方法

阻塞取出一个到期的任务。

<?php
include '../vendor/autoload.php';
// 要与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);

remove 方法

移除一个未到期的任务。

<?php
include '../vendor/autoload.php';
// 要与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);

License

Apache License Version 2.0, http://www.apache.org/licenses/

delayer-client-php's People

Contributors

onanying avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.