Skip to content

Commit 70b3b7a

Browse files
committed
队列实现优化
1 parent 1c61329 commit 70b3b7a

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/Driver/Pool/RedisPool.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,14 @@ public function keepMin(?int $num = null): int
4848
*/
4949
protected function itemIntervalCheck($item): bool
5050
{
51+
if(!isset($item->__lastPingTime)){
52+
$item->__lastPingTime = 0;
53+
}
5154
if(time() - $item->__lastPingTime > 10){
5255
try{
53-
return $item->ping();
56+
$ret = $item->ping();
57+
$item->__lastPingTime = time();
58+
return $ret;
5459
}catch (\Throwable $throwable){
5560
//异常说明该链接出错了,return false 进行回收
5661
return false;

src/Driver/RedisQueue.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
namespace EasySwoole\Queue\Driver;
55

66

7-
use EasySwoole\Pool\MagicPool;
7+
use EasySwoole\Queue\Driver\Pool\RedisPool;
88
use EasySwoole\Queue\Job;
99
use EasySwoole\Queue\QueueDriverInterface;
1010
use EasySwoole\Redis\Config;
@@ -20,11 +20,9 @@ class RedisQueue implements QueueDriverInterface
2020

2121
public function __construct(Config $config,string $queueName = 'es_q')
2222
{
23-
$this->pool = new MagicPool(function ()use($config){
24-
$redis = new Redis($config);
25-
$redis->connect();
26-
return $redis;
27-
});
23+
$poolConfig = new PoolConfig();
24+
$poolConfig->setExtraConf($config);
25+
$this->pool = new RedisPool($poolConfig);
2826
$this->queueName = $queueName;
2927
}
3028

0 commit comments

Comments
 (0)