feat: redis

This commit is contained in:
2025-01-21 16:20:16 +08:00
parent df78fc705d
commit 2beb8d9e55
32 changed files with 310 additions and 84 deletions

View File

@@ -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);
}
}