/** * 连接ssdb */ private function connect() { $host = !empty($this->config['host']) ? $this->config['host'] : '127.0.0.1'; $port = !empty($this->config['port']) ? $this->config['port'] : 8888; $password = !empty($this->config['password']) ? $this->config['password'] : ''; $timeoutms = !empty($this->config['timeoutms']) ? $this->config['timeoutms'] : 1000; try { $this->handler = new \SimpleSSDB($host, $port, $timeoutms); $this->isConnected = true; } catch (SSDBException $ex) { self::exception($ex); $this->isConnected = false; } if ($this->isConnected) { if (!empty($password)) { $this->handler->auth($password); } } }
function KVStorageConnect($host, $port, $pwd, $name) { global $ssdb; global $ssdb_prefix; if (empty($ssdb) == TRUE) { try { $ssdb = new SimpleSSDB($host, $port); if (empty($pwd) == FALSE) { $ssdb->auth(SSDB_PWD); } $ssdb_prefix = $name . '_'; return $ssdb; } catch (SSDBException $e) { if (DEBUG == TRUE) { die('KVStorageConnect Error: ' . $e->getMessage()); } } return FALSE; } return $ssdb; }