initAsynPools

这个方法在1.7.6版本以后才有

用于初始化连接池,可以增加更多的连接池。

    /**
     * 这里可以进行额外的异步连接池,比如另一组redis/mysql连接
     * @return array
     */
    public function initAsynPools()
    {
        parent::initAsynPools();
        $this->addAsynPool('redis2', new RedisAsynPool($this->config, 'test2'));
    }

如上面代码所展示我们增加了一个名为redis2的连接池。

RedisAsynPool的第一个参数传递我们的配置文件这里是$this->config,第二个参数传递的是配置中的目标名称这里是test2。

#redis.php文件
/**
 * 本地环境
 */
$config['redis']['test']['ip'] = '192.168.21.10';
$config['redis']['test']['port'] = 6379;
$config['redis']['test']['select'] = 1;
$config['redis']['test']['password'] = '123456';
$config['redis']['asyn_max_count'] = 10;

/**
 * 本地环境2
 */
$config['redis']['test2']['ip'] = '192.168.21.10';
$config['redis']['test2']['port'] = 6379;
$config['redis']['test2']['select'] = 2;
$config['redis']['test2']['password'] = '123456';
$config['redis']['asyn_max_count'] = 10;

这样一来名为redis2的连接池所访问的便是本地环境2所代表的redis连接了。

关于连接池还有2个方法

*addAsynPool 参考9.25章节

*getAsynPool 参考9.26章节

results matching ""

    No results matching ""