Skip to content

Commit ca9124c

Browse files
author
peter
committed
update
1 parent 7e89eed commit ca9124c

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,23 @@ Hyperf框架与ThinkPHP5相同逻辑处理同一个报告,差距也太大了
5959

6060
2. 基于Redis List队列封装
6161

62-
3. 基于Redis Hash的封装
62+
[拉取亚马逊周期报告队列](./app/Command/Amazon/Report/ReportGetDocument.php)为例
63+
64+
```php
65+
66+
//(new AmazonGetReportDocumentQueue())->pop();//单个请求拉取报告
67+
(new AmazonGetReportDocumentQueue())->coPop(30);//并行拉取30个报告
68+
```
69+
AmazonGetReportDocumentQueue继承[Queue](./app/Queue/Queue.php)类,**handleQueueData**方法为处理队列数据的方法。每个队列类都需要实现**handleQueueData**方法和定义队列名称即可。
70+
71+
Queue类封装了Redis List的常用操作,包括:
72+
1. 入队[push()](./app/Queue/Queue.php#L35)方法
73+
2. 出队单个消费[pop()](./app/Queue/Queue.php#L46)方法和并行消费[coPop()](./app/Queue/Queue.php#L130)方法。其中coPop()方法使用了协程来实现并行消费。(实测性能提升非常大)
74+
3. 获取队列长度[len()](./app/Queue/Queue.php#L227)方法
75+
76+
77+
78+
79+
80+
5. 基于Redis Hash的封装
6381

app/Command/Amazon/Report/ReportGetDocument.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public function configure(): void
3737
*/
3838
public function handle(): void
3939
{
40+
41+
// (new AmazonGetReportDocumentQueue())->pop();//单个请求拉取报告
4042
(new AmazonGetReportDocumentQueue())->coPop(30);//并行请求的数量
4143
}
4244
}

app/Queue/QueueInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,7 @@ public function push(QueueDataInterface $queueData): bool;
2222

2323
public function pop(): bool;
2424

25+
public function coPop(): bool;
26+
2527
public function handleQueueData(QueueDataInterface $queueData): bool;
2628
}

0 commit comments

Comments
 (0)