roleMenuArrKey = AdminRedisKey::adminMenuArrByRoleId($this->roleId); $this->roleMenuListKey = AdminRedisKey::adminMenuListByRoleId($this->roleId); } /** * @param int $roleId * @return array|array[] * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface * @throws \RedisException */ public function getRoleCache(int $roleId): array { $this->roleId = $roleId; $this->getKey(); if ($this->redis->exists($this->roleMenuArrKey,'system') && $this->redis->exists($this->roleMenuListKey,'system')) { return [ 'role_arr' => $this->redis->sMembers($this->roleMenuArrKey,'system'), 'role_list' => json_decode($this->redis->get($this->roleMenuListKey,'system'),true), ]; } if ($this->roleId == RoleCode::SUPER_ADMIN) { $menuIds = $this->adminMenuModel->getAllIds(); $data = (new MenuCache)->getMenu(); // $menuList = $this->adminMenuModel->getAllMenu(); } else { $menuIds = $this->adminRoleMenuModel->getMenuByRoleId($this->roleId); $menuList = $this->adminMenuModel->getRoleMenu($menuIds); $data = $this->getDbMenu($menuList); } if (empty($menuIds) || empty($menuList)) { return [ 'role_arr' => [], 'role_list' => [] ]; } $this->delRoleCache(); $this->redis->set($this->roleMenuListKey,json_encode($data),'system'); $this->redis->sAddBatch($this->roleMenuArrKey,$menuIds,'system'); return [ 'role_arr' => $menuIds, 'role_list' => $data ]; } /** * @param int $roleId * @return void * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface * @throws \RedisException */ public function delRoleCache(int $roleId = 0): void { if ($roleId > 0) { $this->roleId = $roleId; $this->getKey(); } $this->redis->delete($this->roleMenuArrKey,'system'); $this->redis->delete($this->roleMenuListKey,'system'); } }