public function __construct() { parent::__construct(); $config = Config::$redis; $this->connect($config['host'], $config['port']); $this->auth($config['auth']); }
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; } } } }
/** * * 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); } }
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(); }
/** * 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; }
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']); } }
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']); } }
public function __construct() { parent::__construct(); }
public function __construct() { parent::__construct(); $this->connect($this->host, $this->port); $this->auth($this->login); }