<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                2.x配置文件時Config.php ``` 'REDIS'=>[ 'host'=>'127.0.0.1', 'port'=>'6379', 'time_out'=>20 ] ``` 控制器使用 ``` //easySwoole2.x\vendor\easyswoole\easyswoole\src\Config.php use EasySwoole\Config; class xxx{ public xx(){ $redisConfig=Config::getInstance()->getConf("REDIS"); } } ``` ## **配置單獨的配置文件** 項目文件下新建Conf/redis.php ``` return [ 'host'=>'127.0.0.1', 'port'=>'6379', 'time_out'=>20 ]; ``` 在項目的全局事件文件`EasySwooleEvent`中的frameInitialize方法添加`$this->loadConf(EASYSWOOLE_ROOT . '/Conf'); `,然后新建LoadConf方法,注意引入File類 ``` <?php namespace EasySwoole; use \EasySwoole\Core\AbstractInterface\EventInterface; //use \EasySwoole\Core\Component\Di; use App\Lib\Redis\Redis; use EasySwoole\Core\Utility\File; Class EasySwooleEvent implements EventInterface { public static function frameInitialize(): void { date_default_timezone_set('Asia/Shanghai'); // 載入項目 Conf 文件夾中所有的配置文件 self::loadConf(EASYSWOOLE_ROOT . '/Conf'); } public function static loadConf($ConfPath) { //easySwoole2.x\vendor\easyswoole\easyswoole\src\Config.php的命名空間都是EasySwoole這里可以省略 $Conf = Config::getInstance(); $files = File::scanDir($ConfPath); foreach ($files as $file) { $data = require_once $file; $Conf->setConf(strtolower(basename($file, '.php')), (array)$data); } } } ``` Redis.php ``` <?php namespace App\Lib\Redis; use EasySwoole\Core\AbstractInterface\Singleton; use EasySwoole\Config; class Redis{ use Singleton; public $redis=""; private function __construct(){ if (!extension_loaded('redis')) { throw new \Exception("redis擴展未開啟", 1); } try{ $this->redis=new \Redis(); //$result=$this->redis->connect("127.0.0.1", 6379,20); // $redisConfig=Config::getInstance()->getConf("REDIS"); $redisConfig=Config::getInstance()->getConf("redis"); $result=$this->redis->connect($redisConfig['host'], $redisConfig['port'],$redisConfig['time_out']); }catch(\Exception $e){ throw new \Exception("redis鏈接異常", 1); } if ($result===false) { throw new \Exception("redis 鏈接失敗", 1); } } public function get($key){ if (empty($key)) { return ""; } return $this->redis->get($key); } public function set($key,$value){ if (empty($key)||empty($value)) { return ""; } return $this->redis->set($key,$value); } } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看