feat : config

This commit is contained in:
2025-03-20 15:27:53 +08:00
parent ef9f663fb2
commit d3d0cda616
9 changed files with 164 additions and 3 deletions

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