61 lines
1.3 KiB
PHP
61 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Cache\Redis\Common;
|
|
|
|
use App\Cache\Redis\RedisCache;
|
|
use App\Constants\RedisCode;
|
|
use App\Model\Cycle;
|
|
use Hyperf\Di\Annotation\Inject;
|
|
use Psr\Container\ContainerExceptionInterface;
|
|
use Psr\Container\NotFoundExceptionInterface;
|
|
|
|
class CycleCache
|
|
{
|
|
|
|
/**
|
|
* @var RedisCache
|
|
*/
|
|
#[Inject]
|
|
protected RedisCache $redis;
|
|
|
|
/**
|
|
* @var Cycle $cycleModel
|
|
*/
|
|
#[Inject]
|
|
protected Cycle $cycleModel;
|
|
|
|
/**
|
|
* @return void
|
|
* @throws ContainerExceptionInterface
|
|
* @throws NotFoundExceptionInterface
|
|
*/
|
|
public function setAllCycleCache(): void
|
|
{
|
|
$key = CommonRedisKey::getCycleList();
|
|
|
|
if ($this->redis->exists($key,RedisCode::SYSTEM_DB)) return;
|
|
|
|
$allData = $this->cycleModel->get();
|
|
|
|
if (empty($allData)) return;
|
|
|
|
$allData = $allData->toArray();
|
|
|
|
foreach ($allData as $item) {
|
|
$this->redis->zAdd($key, $item['id'],$item['dates'],RedisCode::SYSTEM_DB);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param string $date
|
|
* @return bool|float|\Redis
|
|
* @throws ContainerExceptionInterface
|
|
* @throws NotFoundExceptionInterface
|
|
*/
|
|
public function getCycleCache(string $date): float|bool|\Redis
|
|
{
|
|
$key = CommonRedisKey::getCycleList();
|
|
|
|
return $this->redis->zScore($key,$date,RedisCode::SYSTEM_DB);
|
|
}
|
|
} |