feat: redis
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Cache\Redis\Admin;
|
||||
|
||||
use App\Cache\Redis\RedisCache;
|
||||
use App\Constants\RedisCode;
|
||||
use App\Model\AdminMenu;
|
||||
use App\Service\ServiceTrait\Admin\AdminRoleMenuTrait;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
@@ -48,15 +49,15 @@ class MenuCache
|
||||
*/
|
||||
public function getMenu(): array
|
||||
{
|
||||
if ($this->redis->exists($this->menuKey,'system')) {
|
||||
return json_decode($this->redis->get($this->menuKey,'system'),true);
|
||||
if ($this->redis->exists($this->menuKey,RedisCode::SYSTEM_DB)) {
|
||||
return json_decode($this->redis->get($this->menuKey,RedisCode::SYSTEM_DB),true);
|
||||
}
|
||||
|
||||
$allMenuList = $this->adminMenuModel->getAllMenu();
|
||||
|
||||
$data = $this->getDbMenu($allMenuList);
|
||||
|
||||
$this->redis->set($this->menuKey,json_encode($data),'system');
|
||||
$this->redis->set($this->menuKey,json_encode($data),RedisCode::SYSTEM_DB);
|
||||
|
||||
return $data;
|
||||
}
|
||||
@@ -69,6 +70,6 @@ class MenuCache
|
||||
*/
|
||||
public function delMenu(): void
|
||||
{
|
||||
$this->redis->delete($this->menuKey,'system');
|
||||
$this->redis->delete($this->menuKey,RedisCode::SYSTEM_DB);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ namespace App\Cache\Redis\Admin;
|
||||
use App\Cache\Redis\RedisCache;
|
||||
use App\Constants\Admin\AuthCode;
|
||||
use App\Constants\Common\RoleCode;
|
||||
use App\Constants\RedisCode;
|
||||
use App\Model\AdminMenu;
|
||||
use App\Model\AdminRoleMenu;
|
||||
use App\Service\ServiceTrait\Admin\AdminRoleMenuTrait;
|
||||
@@ -75,10 +76,10 @@ class RoleCache
|
||||
|
||||
$this->getKey();
|
||||
|
||||
if ($this->redis->exists($this->roleMenuArrKey,'system') && $this->redis->exists($this->roleMenuListKey,'system')) {
|
||||
if ($this->redis->exists($this->roleMenuArrKey,RedisCode::SYSTEM_DB) && $this->redis->exists($this->roleMenuListKey,RedisCode::SYSTEM_DB)) {
|
||||
return [
|
||||
'role_arr' => $this->redis->sMembers($this->roleMenuArrKey,'system'),
|
||||
'role_list' => json_decode($this->redis->get($this->roleMenuListKey,'system'),true),
|
||||
'role_arr' => $this->redis->sMembers($this->roleMenuArrKey,RedisCode::SYSTEM_DB),
|
||||
'role_list' => json_decode($this->redis->get($this->roleMenuListKey,RedisCode::SYSTEM_DB),true),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -101,8 +102,8 @@ class RoleCache
|
||||
|
||||
$this->delRoleCache();
|
||||
|
||||
$this->redis->set($this->roleMenuListKey,json_encode($data),'system');
|
||||
$this->redis->sAddBatch($this->roleMenuArrKey,$menuIds,'system');
|
||||
$this->redis->set($this->roleMenuListKey,json_encode($data),RedisCode::SYSTEM_DB);
|
||||
$this->redis->sAddBatch($this->roleMenuArrKey,$menuIds,RedisCode::SYSTEM_DB);
|
||||
|
||||
return [
|
||||
'role_arr' => $menuIds,
|
||||
@@ -124,7 +125,7 @@ class RoleCache
|
||||
$this->getKey();
|
||||
}
|
||||
|
||||
$this->redis->delete($this->roleMenuArrKey,'system');
|
||||
$this->redis->delete($this->roleMenuListKey,'system');
|
||||
$this->redis->delete($this->roleMenuArrKey,RedisCode::SYSTEM_DB);
|
||||
$this->redis->delete($this->roleMenuListKey,RedisCode::SYSTEM_DB);
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Cache\Redis\Admin;
|
||||
|
||||
use App\Cache\Redis\RedisCache;
|
||||
use App\Constants\RedisCode;
|
||||
use App\Model\AdminSection;
|
||||
use App\Service\ServiceTrait\Admin\SectionTrait;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
@@ -49,15 +50,15 @@ class SectionCache
|
||||
*/
|
||||
public function getList(): array
|
||||
{
|
||||
if ($this->redis->exists($this->key,'system')) {
|
||||
return json_decode($this->redis->get($this->key,'system'),true);
|
||||
if ($this->redis->exists($this->key,RedisCode::SYSTEM_DB)) {
|
||||
return json_decode($this->redis->get($this->key,RedisCode::SYSTEM_DB),true);
|
||||
}
|
||||
|
||||
$allList = $this->adminSectionModel->getList();
|
||||
|
||||
$data = $this->getDbList($allList);
|
||||
|
||||
$this->redis->set($this->key,json_encode($data),'system');
|
||||
$this->redis->set($this->key,json_encode($data),RedisCode::SYSTEM_DB);
|
||||
|
||||
return $data;
|
||||
}
|
||||
@@ -70,6 +71,6 @@ class SectionCache
|
||||
*/
|
||||
public function delList()
|
||||
{
|
||||
$this->redis->delete($this->key,'system');
|
||||
$this->redis->delete($this->key,RedisCode::SYSTEM_DB);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace App\Cache\Redis\Admin;
|
||||
|
||||
use App\Cache\Redis\RedisCache;
|
||||
use App\Constants\RedisCode;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
@@ -26,7 +27,7 @@ class UserCache
|
||||
*/
|
||||
public function getAdminToken($userId): false|string
|
||||
{
|
||||
return $this->redis->get(AdminRedisKey::adminUserToken($userId),'system') ?? false;
|
||||
return $this->redis->get(AdminRedisKey::adminUserToken($userId),RedisCode::SYSTEM_DB) ?? false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,7 +42,7 @@ class UserCache
|
||||
public function setAdminToken($userId, string $token, int $ttl): bool
|
||||
{
|
||||
$key = AdminRedisKey::adminUserToken($userId);
|
||||
$this->redis->delete($key,'system');
|
||||
return $this->redis->setEx($key, $token, $ttl, 'system');
|
||||
$this->redis->delete($key,RedisCode::SYSTEM_DB);
|
||||
return $this->redis->setEx($key, $token, $ttl, RedisCode::SYSTEM_DB);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user