106 Star 392 Fork 93

swoole / framework

Create your Gitee Account
Explore and code with more than 6 million developers,Free private repositories !:)
Sign up
Clone or download
Redis.php 1.45 KB
Copy Edit Web IDE Raw Blame History
韩天峰 authored 2016-08-30 17:16 . 调整连接池细节
<?php
namespace Swoole\Async;
use Swoole;
class Redis extends Pool
{
const DEFAULT_PORT = 6379;
function __construct($config = array(), $poolSize = 100)
{
if (empty($config['host']))
{
throw new Swoole\Exception\InvalidParam("require redis host option.");
}
if (empty($config['port']))
{
$config = self::DEFAULT_PORT;
}
parent::__construct($config, $poolSize);
$this->create(array($this, 'connect'));
}
protected function connect()
{
$redis = new \swoole_redis();
$redis->on('close', function ($redis)
{
$this->remove($redis);
});
return $redis->connect($this->config['host'], $this->config['port'], function ($redis, $result)
{
if ($result)
{
$this->join($redis);
}
else
{
$this->failure();
trigger_error("connect to redis server[{$this->config['host']}:{$this->config['port']}] failed. Error: {$redis->errMsg}[{$redis->errCode}].");
}
});
}
function __call($call, $params)
{
return $this->request(function (\swoole_redis $redis) use ($call, $params)
{
call_user_func_array(array($redis, $call), $params);
//必须要释放资源,否则无法被其他重复利用
$this->release($redis);
});
}
}

Comment ( 1 )

Sign in for post a comment

PHP
1
https://git.oschina.net/swoole/swoole_framework.git
git@git.oschina.net:swoole/swoole_framework.git
swoole
swoole_framework
framework
master

Search