swoole-framwork/core/init/RedisHelper.php
2024-05-22 15:50:08 +08:00

36 lines
1.1 KiB
PHP

<?php
namespace Core\init;
use Core\BeanFactory;
use Core\lib\PHPRedisPool;
use phpDocumentor\Reflection\Types\Array_;
use Core\annotations\Bean;
/**
* @Bean()
* Class RedisHelper
* @method static string get(string $key)
* @method static bool set(string $key,string $value)
* @method static bool setex(string $key,int $ttl,string $value)
* @method static array hgetall(string $key)
* @method static bool hmset(string $key,array $keyandvalues)
* @method static bool zAdd(string $key, int $score, string $member)
* @method static mixed eval($script, $args=array(),$numberKeys=0)
*/
class RedisHelper{
public static function __callStatic($name, $arguments)
{
/** @var $pool PHPRedisPool */
$pool=BeanFactory::getBean(PHPRedisPool::class);
$redis_obj=$pool->getConnection();
try{
if(!$redis_obj) {
return false;
}
return $redis_obj->redis->$name(...$arguments);
}catch (\Exception $exception){
return $exception->getMessage();
}finally{
if($redis_obj)
$pool->close($redis_obj);
}
}
}