<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>

                # Redis [TOC] SD提供了Redis異步連接池,連接池的使用和正常Redis擴展一樣。 ## 創建Redis連接池 在SD的initAsynPools方法中已經創建好了redis和mysql默認的連接池。 ``` /** * 初始化各種連接池 * @param $workerId */ public function initAsynPools($workerId) { $this->asynPools = []; if ($this->config->get('redis.enable', true)) { $this->asynPools['redisPool'] = new RedisAsynPool($this->config, $this->config->get('redis.active')); } if ($this->config->get('mysql.enable', true)) { $this->asynPools['mysqlPool'] = new MysqlAsynPool($this->config, $this->config->get('mysql.active')); } $this->redis_pool = $this->asynPools['redisPool'] ?? null; $this->mysql_pool = $this->asynPools['mysqlPool'] ?? null; } ``` 如果你想創建多個Redis連接池可以仿照上面的方法。 ``` $this->addAsynPool('redisPool2', new RedisAsynPool($this->config, ‘redis2’); ``` ## 獲取Redis連接池 在Controller,Model,Task共同的基類CoreBase中默認獲取了RedisPool。 ``` /** * 當被loader時會調用這個方法進行初始化 * @param $context */ public function initialization(&$context) { $this->setContext($context); $this->redis = $this->loader->redis("redisPool"); $this->db = $this->loader->mysql("mysqlPool",$this); } ``` ## 使用方法 Redis的使用方法和PhpRedis擴展一致,可以參考ServerRedisTest,這是關于Redis的測試用例。 ``` $value = $this->redis->set('test', 'testRedis'); ``` ## Redis-LUA SD支持Redis-LUA,根目錄下有個名為lua的文件夾,這里的lua腳本都會自動被SD加載進Redis中。 ``` public function http_testRedisLua() { $value = $this->redis->evalSha(getLuaSha1('sadd_from_count'), ['testlua', 100], 2, [1, 2, 3]); $this->http_output->end($value); } ``` 通過evalSha和getLuaSha1方法配合我們可以非常容易的使用Redis-LUA功能。其中sadd_from_count是lua文件夾某一個lua腳本的文件名。 在SD啟動時我們也能看到加載了哪些lua腳本,如果redis服務器不支持lua也會有相應的提示。 ![](https://box.kancloud.cn/6aa55e3de0a42ad861f98374ab792608_512x148.png) ## 同步Redis ``` $redisSync = $this->redis_pool->getSync(); ``` 通過getSync返回一個同步的redis連接。
                  <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>

                              哎呀哎呀视频在线观看