/** * 连接redis */ private function connect() { $host = !empty($this->config['host']) ? $this->config['host'] : '127.0.0.1'; $port = !empty($this->config['port']) ? $this->config['port'] : 6379; $password = !empty($this->config['password']) ? $this->config['password'] : ''; $database = !empty($this->config['database']) ? $this->config['database'] : 0; $timeout = !empty($this->config['timeout']) ? $this->config['timeout'] : 1; $persistent = isset($this->config['persistent']) ? $this->config['persistent'] : false; $func = $persistent ? 'pconnect' : 'connect'; if (empty($timeout)) { $this->isConnected = $this->handler->{$func}($host, $port); } else { $this->isConnected = $this->handler->{$func}($host, $port, $timeout); } if ($this->isConnected) { if (!empty($password)) { $this->handler->auth($password); } if ($database) { $this->handler->select($database); } } }