protected function _init() { try { if (null == $this->_conn) { $config = $this->_config['config']; $t = explode('/', $config['dsn']); $db = isset($t[1]) ? $t[1] : 0; $t = explode(':', $t[0]); $redis = new Connection(); $redis->connect($t[0], $t[1]); if (isset($config['auth'])) { $redis->auth($config['auth']); } $redis->select($db); $this->_conn = $redis; } } catch (\RedisException $re) { throw new Exception($re->getMessage(), $re->getCode(), $re); } }
/** * get Redis Connection instance * * @param string|array $config the connect name * * @throws \RedisException * @return \Flywheel\Redis\Connection */ public static function getConnection($config = null) { if (null == $config || is_string($config)) { $c = ConfigHandler::get('redis'); if (null == $config || !isset($c[$config])) { $config = $c['__default__']; } if (!isset($c[$config])) { throw new \RedisException("Connection config not found with '{$config}'"); } $config = $c[$config]; } return Connection::getInstance($config['dsn'], isset($config['option']) && $config['option'] ? $config['option'] : array()); }