<?php
namespace AppLibRedis;
use EasySwooleConfig;
use EasySwooleCoreAbstractInterfaceSingleton;
class Redis
{
use Singleton;
public $redis = "";
private function __construct()
{
if (!extension_loaded('redis')) {
throw new Exception("redis.so文件不存在");
}
try {
$this->redis = new Redis();
// 读取config.php
// $redisConfig = Config::getInstance()->getConf("redis");
$redisConfig = Yaconf::get('redis');
// var_dump($redisConfig);
$result = $this->redis->connect($redisConfig['host'], $redisConfig['port'], $redisConfig['time_out']);
} catch (Exception $e) {
// throw new Exception($e->getMessage());
throw new Exception('redis异常');
}
if ($result === false) {
throw new Exception('redis 连接失败');
}
}
public function get($key)
{
if (empty($key)) {
return '';
}
return $this->redis->get($key);
}
}
php.ini如下
运行
php easyswoole start