feat: jwt
This commit is contained in:
47
app/Cache/Redis/Admin/UserCache.php
Normal file
47
app/Cache/Redis/Admin/UserCache.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Cache\Redis\Admin;
|
||||
|
||||
use App\Cache\Redis\RedisCache;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
class UserCache
|
||||
{
|
||||
/**
|
||||
* @var RedisCache $redis
|
||||
*/
|
||||
#[Inject]
|
||||
protected RedisCache $redis;
|
||||
|
||||
/**
|
||||
* @param $userId
|
||||
* @return string|false
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws \RedisException
|
||||
*/
|
||||
public function getAdminToken($userId): false|string
|
||||
{
|
||||
return $this->redis->get(AdminRedisKey::adminUserToken($userId),'system') ?? false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $userId
|
||||
* @param string $token
|
||||
* @param int $ttl
|
||||
* @return bool
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws \RedisException
|
||||
*/
|
||||
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');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user