feat : config
This commit is contained in:
55
app/Cache/Redis/Api/UserCache.php
Normal file
55
app/Cache/Redis/Api/UserCache.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Cache\Redis\Api;
|
||||
|
||||
use App\Cache\Redis\Common\CommonRedisKey;
|
||||
use App\Cache\Redis\RedisCache;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
class UserCache
|
||||
{
|
||||
/**
|
||||
* @var RedisCache
|
||||
*/
|
||||
#[Inject]
|
||||
protected RedisCache $redis;
|
||||
|
||||
/**
|
||||
* @param int $userId
|
||||
* @param string $token
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function setUserToken(int $userId,string $token): void
|
||||
{
|
||||
$key = CommonRedisKey::userTokenHashKey();
|
||||
$this->redis->hSet($key, $userId, $token);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $userId
|
||||
* @return false|mixed|\Redis|string
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function getUserToken(int $userId): mixed
|
||||
{
|
||||
$key = CommonRedisKey::userTokenHashKey();
|
||||
return $this->redis->hGet($key, $userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $userId
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function removeUserToken(int $userId): void
|
||||
{
|
||||
$key = CommonRedisKey::userTokenHashKey();
|
||||
$this->redis->hDel($key, $userId);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user