public function getClient()
	{
		if ($this->_client === null) {
			$this->_client = new \Redis;
			$this->_client->connect($this->hostname, $this->port, $this->database);
			$slaveenable = false;
			if ($this->enableSlaves) {
				while(count($this->slaves)>0){
					$this->_slave = new \Redis();
					$select_slave = self::getByWeight($this->slaves);//随机访问一台redis从服务器
					$slaveenable = $this->_slave->connect($select_slave['hostname'], $select_slave['port'], $this->database);
					if ($slaveenable) {
						if (isset($select_slave['password'])) {
							if ($this->_slave->auth($select_slave['password']) === false) {
								throw new InvalidConfigException('Redis Slave authentication failed!');
							}
						}
						break;
					}			
				}
			}
			if (!$slaveenable) {
				$this->_slave = $this->_client;
				$this->enableSlaves = false;
			}
			if (isset($this->password)) {
				if ($this->_client->auth($this->password) === false) {
					throw new InvalidConfigException('Redis authentication failed!');
				}
			}
			//$this->_client->select($this->database);
		}
		return $this->_client;
	}
public function getClient()
	{
		if ($this->_client === null) {
			$this->_client = new \Redis;
			$this->_client->connect($this->hostname, $this->port, $this->database);
			$slaveenable = false;
			if ($this->enableSlaves) {
				while(count($this->slaves)>0){
					$this->_slave = new \Redis();
					$select_slave = self::getByWeight($this->slaves);//随机访问一台redis从服务器
					$slaveenable = $this->_slave->connect($select_slave['hostname'], $select_slave['port'], $this->database);
					if ($slaveenable) {
						if (isset($select_slave['password'])) {
							if ($this->_slave->auth($select_slave['password']) === false) {
								throw new InvalidConfigException('Redis Slave authentication failed!');
							}
						}
						break;
					}			
				}
			}
			if (!$slaveenable) {
				$this->_slave = $this->_client;
				$this->enableSlaves = false;
			}
			if (isset($this->password)) {
				if ($this->_client->auth($this->password) === false) {
					throw new InvalidConfigException('Redis authentication failed!');
				}
			}
			//$this->_client->select($this->database);
		}
		return $this->_client;
	}
public function getClient ( ) { if ( $ this -> _client === null ) { $ this -> _client = new \ Redis ; $ this -> _client -> connect ( $ this -> hostname , $ this -> port , $ this -> database ) ; $ slaveenable = false ; if ( $ this -> enableSlaves ) { while ( count ( $ this -> slaves ) > 0 ) { $ this -> _slave = new \ Redis ( ) ; $ select_slave = self :: getByWeight ( $ this -> slaves ) ; //随机访问一台redis从服务器 $ slaveenable = $ this -> _slave -> connect ( $ select_slave [ 'hostname' ] , $ select_slave [ 'port' ] , $ this -> database ) ; if ( $ slaveenable ) { if ( isset ( $ select_slave [ 'password' ] ) ) { if ( $ this -> _slave -> auth ( $ select_slave [ 'password' ] ) === false ) { throw new InvalidConfigException ( 'Redis Slave authentication failed!' ) ; } } break ; } } } if ( ! $ slaveenable ) { $ this -> _slave = $ this -> _client ; $ this -> enableSlaves = false ; } if ( isset ( $ this -> password ) ) { if ( $ this -> _client -> auth ( $ this -> password ) === false ) { throw new InvalidConfigException ( 'Redis authentication failed!' ) ; } } //$this->_client->select($this->database); } return $ this -> _client ; }
Gets the redis client
@return \Redis the redis client
Gets the redis client