75 lines
1.5 KiB
PHP
75 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Cache\Redis\Admin;
|
|
|
|
use App\Cache\Redis\RedisCache;
|
|
use App\Model\AdminSection;
|
|
use App\Service\ServiceTrait\Admin\SectionTrait;
|
|
use Hyperf\Di\Annotation\Inject;
|
|
use Psr\Container\ContainerExceptionInterface;
|
|
use Psr\Container\NotFoundExceptionInterface;
|
|
use RedisException;
|
|
|
|
class SectionCache
|
|
{
|
|
use SectionTrait;
|
|
|
|
/**
|
|
* @var AdminSection
|
|
*/
|
|
#[Inject]
|
|
protected AdminSection $adminSectionModel;
|
|
|
|
/**
|
|
* @var RedisCache $redis
|
|
*/
|
|
#[Inject]
|
|
protected RedisCache $redis;
|
|
|
|
/**
|
|
* 菜单
|
|
* @var string
|
|
*/
|
|
protected string $key;
|
|
|
|
|
|
/**
|
|
* 构造函数注入 key
|
|
*/
|
|
public function __construct()
|
|
{
|
|
$this->key = AdminRedisKey::adminSectionList();
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
* @throws ContainerExceptionInterface
|
|
* @throws NotFoundExceptionInterface
|
|
* @throws RedisException
|
|
*/
|
|
public function getList(): array
|
|
{
|
|
if ($this->redis->exists($this->key,'system')) {
|
|
return json_decode($this->redis->get($this->key,'system'),true);
|
|
}
|
|
|
|
$allList = $this->adminSectionModel->getList();
|
|
|
|
$data = $this->getDbList($allList);
|
|
|
|
$this->redis->set($this->key,json_encode($data),'system');
|
|
|
|
return $data;
|
|
}
|
|
|
|
/**
|
|
* @return void
|
|
* @throws ContainerExceptionInterface
|
|
* @throws NotFoundExceptionInterface
|
|
* @throws RedisException
|
|
*/
|
|
public function delList()
|
|
{
|
|
$this->redis->delete($this->key,'system');
|
|
}
|
|
} |