Skip to content

Commit

Permalink
队列实现优化
Browse files Browse the repository at this point in the history
  • Loading branch information
kiss291323003 committed Feb 16, 2023
1 parent 1c61329 commit 70b3b7a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
7 changes: 6 additions & 1 deletion src/Driver/Pool/RedisPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,14 @@ public function keepMin(?int $num = null): int
*/
protected function itemIntervalCheck($item): bool
{
if(!isset($item->__lastPingTime)){
$item->__lastPingTime = 0;
}
if(time() - $item->__lastPingTime > 10){
try{
return $item->ping();
$ret = $item->ping();
$item->__lastPingTime = time();
return $ret;
}catch (\Throwable $throwable){
//异常说明该链接出错了,return false 进行回收
return false;
Expand Down
10 changes: 4 additions & 6 deletions src/Driver/RedisQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace EasySwoole\Queue\Driver;


use EasySwoole\Pool\MagicPool;
use EasySwoole\Queue\Driver\Pool\RedisPool;
use EasySwoole\Queue\Job;
use EasySwoole\Queue\QueueDriverInterface;
use EasySwoole\Redis\Config;
Expand All @@ -20,11 +20,9 @@ class RedisQueue implements QueueDriverInterface

public function __construct(Config $config,string $queueName = 'es_q')
{
$this->pool = new MagicPool(function ()use($config){
$redis = new Redis($config);
$redis->connect();
return $redis;
});
$poolConfig = new PoolConfig();
$poolConfig->setExtraConf($config);
$this->pool = new RedisPool($poolConfig);
$this->queueName = $queueName;
}

Expand Down

0 comments on commit 70b3b7a

Please sign in to comment.