Skip to content

Commit ae82fda

Browse files
committed
修改 README.md
1 parent aaabf01 commit ae82fda

File tree

1 file changed

+89
-8
lines changed

1 file changed

+89
-8
lines changed

README.md

Lines changed: 89 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,108 @@
44

55
## 安装
66

7+
通过 Composer 安装使用:
8+
79
```shell
810
composer require mixstart/delayer-client-php:1.*
911
```
1012

1113
## DEMO
1214

13-
### `push`
15+
### `push` 方法
1416

15-
[client_push_test.php](https://github.com/mixstart/delayer-client-php/blob/master/tests/client_push_test.php)
17+
放入一个任务。
1618

17-
### `pop`
19+
```php
20+
<?php
21+
include '../vendor/autoload.php';
22+
// 要与Delayer服务器端配置的redis的信息相同
23+
$config = [
24+
'host' => '127.0.0.1',
25+
'port' => 6379,
26+
'database' => 0,
27+
'password' => '',
28+
];
29+
$client = new \Delayer\Client($config);
30+
// 任务数据,用户自己定义
31+
$data = [
32+
'orderID' => '2018101712578956648885474',
33+
'action' => 'close',
34+
];
35+
$message = new \Delayer\Message([
36+
// 任务ID,必须全局唯一
37+
'id' => md5(uniqid(mt_rand(), true)),
38+
// 主题,取出任务时需使用
39+
'topic' => 'close_order',
40+
// 必须转换为string类型
41+
'body' => json_encode($data),
42+
]);
43+
$ret = $client->push($message, 20, 604800);
44+
var_dump($ret);
45+
```
1846

19-
[client_pop_test.php](https://github.com/mixstart/delayer-client-php/blob/master/tests/client_pop_test.php)
47+
### `pop` 方法
2048

21-
### `bPop`
49+
取出一个到期的任务。
2250

23-
[client_bpop_test.php](https://github.com/mixstart/delayer-client-php/blob/master/tests/client_bpop_test.php)
51+
```php
52+
<?php
53+
include '../vendor/autoload.php';
54+
// 要与Delayer服务器端配置的redis的信息相同
55+
$config = [
56+
'host' => '127.0.0.1',
57+
'port' => 6379,
58+
'database' => 0,
59+
'password' => '',
60+
];
61+
$client = new \Delayer\Client($config);
62+
$message = $client->pop('close_order');
63+
// 没有任务时,返回false
64+
var_dump($message);
65+
var_dump($message->body);
66+
```
2467

25-
### `remove`
68+
### `bPop` 方法
2669

27-
[client_remove_test.php](https://github.com/mixstart/delayer-client-php/blob/master/tests/client_remove_test.php)
70+
阻塞取出一个到期的任务。
71+
72+
```php
73+
<?php
74+
include '../vendor/autoload.php';
75+
// 要与Delayer服务器端配置的redis的信息相同
76+
$config = [
77+
'host' => '127.0.0.1',
78+
'port' => 6379,
79+
'database' => 0,
80+
'password' => '',
81+
];
82+
$client = new \Delayer\Client($config);
83+
$message = $client->bPop('close_order', 10);
84+
// 没有任务时,返回false
85+
var_dump($message);
86+
var_dump($message->body);
87+
```
88+
89+
### `remove` 方法
90+
91+
移除一个未到期的任务。
92+
93+
```php
94+
<?php
95+
include '../vendor/autoload.php';
96+
// 要与Delayer服务器端配置的redis的信息相同
97+
$config = [
98+
'host' => '127.0.0.1',
99+
'port' => 6379,
100+
'database' => 0,
101+
'password' => '',
102+
];
103+
$client = new \Delayer\Client($config);
104+
// push时定义的任务ID
105+
$id = '***';
106+
$ret = $client->remove($id);
107+
var_dump($ret);
108+
```
28109

29110
## License
30111

0 commit comments

Comments
 (0)