framework/caching/CRedisCache.php
private function parseResponse()
	{
		if(($line=fgets($this->_socket))===false)
			throw new CException('Failed reading data from redis connection socket.');
		$type=$line[0];
		$line=substr($line,1,-2);
		switch($type)
		{
			case '+': // Status reply
				return true;
			case '-': // Error reply
				throw new CException('Redis error: '.$line);
			case ':': // Integer reply
				// no cast to int as it is in the range of a signed 64 bit integer
				return $line;
			case '$': // Bulk replies
				if($line=='-1')
					return null;
				$length=$line+2;
				$data='';
				while($length>0)
				{
					if(($block=fread($this->_socket,$length))===false)
						throw new CException('Failed reading data from redis connection socket.');
					$data.=$block;
					$length-=$this->byteLength($block);
				}
				return substr($data,0,-2);
			case '*': // Multi-bulk replies
				$count=(int)$line;
				$data=array();
				for($i=0;$i<$count;$i++)
					$data[]=$this->parseResponse();
				return $data;
			default:
				throw new CException('Unable to parse data received from redis.');
		}
	}
private function parseResponse()
	{
		if(($line=fgets($this->_socket))===false)
			throw new CException('Failed reading data from redis connection socket.');
		$type=$line[0];
		$line=substr($line,1,-2);
		switch($type)
		{
			case '+': // Status reply
				return true;
			case '-': // Error reply
				throw new CException('Redis error: '.$line);
			case ':': // Integer reply
				// no cast to int as it is in the range of a signed 64 bit integer
				return $line;
			case '$': // Bulk replies
				if($line=='-1')
					return null;
				$length=$line+2;
				$data='';
				while($length>0)
				{
					if(($block=fread($this->_socket,$length))===false)
						throw new CException('Failed reading data from redis connection socket.');
					$data.=$block;
					$length-=$this->byteLength($block);
				}
				return substr($data,0,-2);
			case '*': // Multi-bulk replies
				$count=(int)$line;
				$data=array();
				for($i=0;$i<$count;$i++)
					$data[]=$this->parseResponse();
				return $data;
			default:
				throw new CException('Unable to parse data received from redis.');
		}
	}
private function parseResponse ( ) { if ( ( $ line = fgets ( $ this -> _socket ) ) === false ) throw new CException ( 'Failed reading data from redis connection socket.' ) ; $ type = $ line [ 0 ] ; $ line = substr ( $ line , 1 , - 2 ) ; switch ( $ type ) { case '+' : // Status reply return true ; case '-' : // Error reply throw new CException ( 'Redis error: ' . $ line ) ; case ':' : // Integer reply // no cast to int as it is in the range of a signed 64 bit integer return $ line ; case '$' : // Bulk replies if ( $ line == '-1' ) return null ; $ length = $ line + 2 ; $ data = '' ; while ( $ length > 0 ) { if ( ( $ block = fread ( $ this -> _socket , $ length ) ) === false ) throw new CException ( 'Failed reading data from redis connection socket.' ) ; $ data .= $ block ; $ length -= $ this -> byteLength ( $ block ) ; } return substr ( $ data , 0 , - 2 ) ; case '*' : // Multi-bulk replies $ count = ( int ) $ line ; $ data = array ( ) ; for ( $ i = 0 ; $ i < $ count ; $ i ++ ) $ data [ ] = $ this -> parseResponse ( ) ; return $ data ; default : throw new CException ( 'Unable to parse data received from redis.' ) ; } }
Reads the result from socket and parses it
@return array|bool|null|string
@throws CException socket or data problems
Reads the result from socket and parses it