feat : config
This commit is contained in:
@@ -7,6 +7,7 @@ use App\Constants\ConfigCode;
|
||||
use App\Constants\RedisCode;
|
||||
use App\Model\Config;
|
||||
use App\Model\Cycle;
|
||||
use App\Service\ServiceTrait\Common\OssTrait;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Hyperf\Tappable\HigherOrderTapProxy;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
@@ -14,6 +15,7 @@ use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
class ConfigCache
|
||||
{
|
||||
use OssTrait;
|
||||
|
||||
/**
|
||||
* @var RedisCache
|
||||
@@ -62,21 +64,29 @@ class ConfigCache
|
||||
|
||||
/**
|
||||
* @param $key
|
||||
* @param int $isRedis
|
||||
* @param int $isRedis //默认走缓存 可以关闭
|
||||
* @param int $expire
|
||||
* @return false|HigherOrderTapProxy|mixed|\Redis|string
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function getConfigValueByKey($key, int $isRedis = 0,int $expire = 600): mixed
|
||||
public function getConfigValueByKey($key, int $isRedis = 1,int $expire = 600): mixed
|
||||
{
|
||||
$redisKey = CommonRedisKey::getConfigKey($key);
|
||||
|
||||
if (!$this->redis->exists($redisKey,RedisCode::SYSTEM_DB)) {
|
||||
$value = $this->configModel->where('key',$key)->value('value');
|
||||
|
||||
// 做转换
|
||||
$value = match ($key) {
|
||||
ConfigCode::APP_LOGO => $this->getOssObjectById($value),
|
||||
default => $value,
|
||||
};
|
||||
|
||||
if ($isRedis == 1) {
|
||||
$this->redis->setEx($redisKey, $value, $expire,RedisCode::SYSTEM_DB);
|
||||
}
|
||||
|
||||
return $value ?? ConfigCode::DEFAULT_VALUE[$key];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user