本文整理汇总了PHP中Redis::__construct方法的典型用法代码示例。如果您正苦于以下问题:PHP Redis::__construct方法的具体用法?PHP Redis::__construct怎么用?PHP Redis::__construct使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Redis
的用法示例。
在下文中一共展示了Redis::__construct方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct()
{
parent::__construct();
$config = Config::$redis;
$this->connect($config['host'], $config['port']);
$this->auth($config['auth']);
}
示例2: __construct
public function __construct($params = array())
{
parent::__construct();
$this->ci =& get_instance();
$configFile = 'redis';
$this->ci->config->load($configFile, true);
$servers = $this->ci->config->item('servers', $configFile);
$timeout = $this->ci->config->item('timeout', $configFile);
$dbName = isset($params['db_name']) ? $params['db_name'] : 'web_db';
$database = $this->ci->config->item($dbName, $configFile);
$succ = false;
$i = -1;
$retry = 3;
shuffle($servers);
while (!$succ && $retry--) {
$i = ($i + 1) % count($servers);
$server = $servers[$i];
try {
$succ = $this->connect($server['host'], $server['port'], $timeout);
$succ = $this->select($database);
} catch (Exception $e) {
if ($retry == 1) {
$logParams = array('host' => $server['host'], 'port' => $server['port'], 'timeout' => $timeout, 'message' => $e->getMessage());
$this->ci->log->log('error', 'connect to redis failed', $logParams);
throw $e;
}
}
}
}
示例3: exit
/**
*
* redis 构造函数
*
* @param array $config
*
* @return \Redis
*/
function __construct($config)
{
parent::__construct();
$this->config = array_merge($this->config, $config);
if (php_sapi_name() == 'cli') {
if ($this->connect($config['host'], $config['port'], $config['timeout']) == false) {
echo "Redis '{$config['host']}' Connected Failed. \n";
exit($this->getLastError());
}
} else {
if ($this->pconnect($config['host'], $config['port'], $config['timeout']) == false) {
echo "Redis '{$config['host']}' Connected Failed. \n";
exit($this->getLastError());
}
}
if ($config['password']) {
if ($this->auth($config['password']) == false) {
echo "Redis '{$config['host']}' Password Is Incorrect. \n";
exit($this->getLastError());
}
}
//选择库
$this->select($config['database']);
//开启自动序列化
if ($config['serialization']) {
$this->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP);
}
}
示例4: __construct
public function __construct($host, $database = 0, $password = null, $timeout = 0)
{
parent::__construct();
$server = explode(':', $host);
$this->host = $server[0];
$this->port = $server[1];
$this->password = $password;
$this->timeout = $timeout;
$this->establishConnection();
}
示例5: __construct
/**
* constructor method
*
* @param string $name Name of the connection
* @param string $environment The kernel environment variable
* @param array $parameters Configuration parameters
*/
public function __construct($name, $environment, array $parameters = [])
{
parent::__construct();
if ($parameters['skip_env']) {
$prefix = $name . ':';
} else {
$prefix = $name . '.' . $environment . ':';
}
if (empty($parameters['prefix'])) {
$parameters['prefix'] = $prefix;
} else {
$parameters['prefix'] .= '.' . $prefix;
}
$this->name = $name;
$this->parameters = $parameters;
}
示例6: __construct
public function __construct($redisconfig = array())
{
parent::__construct();
if (empty($redisconfig)) {
$redisconfigs = load_config("redis");
$redisconfig = $redisconfigs['default'];
}
if (!empty($redisconfig['host']) && empty($redisconfig['port']) && empty($redisconfig['timeout'])) {
parent::connect($redisconfig['host']);
} else {
if (!empty($redisconfig['host']) && !empty($redisconfig['port']) && empty($redisconfig['timeout'])) {
parent::connect($redisconfig['host'], $redisconfig['port']);
} else {
if (!empty($redisconfig['host']) && !empty($redisconfig['port']) && !empty($redisconfig['timeout'])) {
parent::connect($redisconfig['host'], $redisconfig['port'], $redisconfig['timeout']);
}
}
}
if (!empty($redisconfig['auth'])) {
parent::auth($redisconfig['auth']);
}
}
示例7: __construct
public function __construct($namespace = null, $config = [])
{
parent::__construct();
$namespace = $namespace ?: __NAMESPACE__;
$defaults = static::$_defaults;
static::$_defaults = Hash::merge(self::$_defaults, static::$_defaults);
$this->_config = $this->_config($namespace, $config);
static::$_defaults = $defaults;
// настраиваем тестовое окружение
$connection = defined('TESTING_IS_GOING_ON') && TESTING_IS_GOING_ON && !empty($this->_config['test']) ? $this->_config['test'] : $this->_config['server'];
// коннектимся
$this->connect($connection['host'], $connection['port']);
// если есть пароль то логинимся
if (!empty($connection['password'])) {
if (!$this->auth($connection['password'])) {
throw new Exception('Wrong password');
}
}
if (!empty($connection['database'])) {
$this->select($connection['database']);
}
}
示例8: __construct
public function __construct()
{
parent::__construct();
}
示例9: __construct
public function __construct()
{
parent::__construct();
$this->connect($this->host, $this->port);
$this->auth($this->login);
}