2021-05-21 22:56:42 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Cache;
|
|
|
|
|
|
|
|
use App\Cache\Repository\HashRedis;
|
2021-07-29 23:30:42 +08:00
|
|
|
use App\Traits\StaticInstance;
|
2021-05-21 22:56:42 +08:00
|
|
|
|
2021-05-22 20:54:30 +08:00
|
|
|
/**
|
|
|
|
* 服务运行ID - 缓存助手
|
|
|
|
*
|
|
|
|
* @package App\Cache
|
|
|
|
*/
|
2021-05-21 22:56:42 +08:00
|
|
|
class ServerRunID extends HashRedis
|
|
|
|
{
|
2021-07-29 23:30:42 +08:00
|
|
|
use StaticInstance;
|
|
|
|
|
2021-05-21 22:56:42 +08:00
|
|
|
protected $prefix = 'SERVER_RUN_ID';
|
|
|
|
|
|
|
|
protected $name = '';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 运行检测超时时间(单位秒)
|
|
|
|
*/
|
|
|
|
const RUN_OVERTIME = 35;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取服务ID列表
|
|
|
|
*
|
|
|
|
* @param int $type 获取类型[1:正在运行;2:已超时;3:所有]
|
|
|
|
* @return array
|
|
|
|
*/
|
2021-05-22 20:54:30 +08:00
|
|
|
public function getServerRunIdAll(int $type = 1): array
|
2021-05-21 22:56:42 +08:00
|
|
|
{
|
|
|
|
$arr = $this->all();
|
|
|
|
|
|
|
|
if ($type == 3) return $arr;
|
|
|
|
|
|
|
|
$current_time = time();
|
|
|
|
return array_filter($arr, function ($value) use ($current_time, $type) {
|
|
|
|
if ($type == 1) {
|
|
|
|
return ($current_time - intval($value)) <= self::RUN_OVERTIME;
|
|
|
|
} else {
|
|
|
|
return ($current_time - intval($value)) > self::RUN_OVERTIME;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|