File tree Expand file tree Collapse file tree 3 files changed +23
-1
lines changed
Expand file tree Collapse file tree 3 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -59,5 +59,23 @@ Hyperf框架与ThinkPHP5相同逻辑处理同一个报告,差距也太大了
5959
60602 . 基于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
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments