Files
cycle_api/app/Cache/Base/SetBaseCache.php
2024-03-25 06:15:36 +08:00

60 lines
1.2 KiB
PHP

<?php
namespace App\Cache\Base;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Redis;
//无序集合缓存基类
abstract class SetBaseCache
{
protected $client;
protected string $prefix = 'Set:'; //缓存前缀
protected string $set_name = ''; //集合名
const CACHE_TTL = 60 * 60 * 24 * 3; //缓存时间 3天
function getRedis()
{
if(!$this->client) $this->client = Redis::client();
return $this->client ;
}
function getAll(): bool
{
return $this->getRedis()->sMembers($this->getSetName());
}
function checkKey($value): bool
{
return $this->getRedis()->sIsMember($this->getSetName(),$value);
}
function setKey($value): bool
{
return $this->getRedis()->sAdd($this->getSetName(),$value);
}
function removeKey($value): bool
{
return $this->getRedis()->sRem($this->getSetName(),$value);
}
function getCount()
{
return $this->getRedis()->sCard($this->getSetName());
}
function getPrefix(): string
{
return $this->prefix;
}
function getSetName(): string
{
return $this->getPrefix().$this->set_name;
}
}