<commit_before><?php namespace Illuminate\Redis;

class Database {

	/**
	 * The host address of the database.
	 *
	 * @var string
	 */
	protected $host;

	/**
	 * The port of the database.
	 *
	 * @var int
	 */
	protected $port;

	/**
	 * The database number to be selected.
	 *
	 * @var int
	 */
	protected $database;

	/**
	 * The Redis connection handler.
	 *
	 * @var resource
	 */
	protected $connection;

	/**
	 * Create a new Redis connection instance.
	 *
	 * @param  string  $host
	 * @param  int     $port
	 * @param  int     $database
	 * @return void
	 */
	public function __construct($host, $port, $database = 0)
	{
		$this->host = $host;
		$this->port = $port;
		$this->database = $database;
	}

	/**
	 * Connect to the Redis database.
	 *
	 * @return void
	 */
	public function connect()
	{
		if ( ! is_null($this->connection)) return;

		$this->connection = $this->openSocket();

		$this->command('select', array($this->database));
	}

	/**
	 * Run a command against the Redis database.
	 *
	 * @param  string  $method
	 * @param  array   $parameters
	 * @return mixed
	 */
	public function command($method, array $parameters = array())
	{
		$this->fileWrite($this->buildCommand($method, $parameters));

		return $this->parseResponse($this->fileGet(512));
	}

	/**
	 * Build the Redis command syntax.
	 *
	 * Redis protocol states that a command should conform to the following format:
	 *
	 *     *<number of arguments> CR LF
	 *     $<number of bytes of argument 1> CR LF
	 *     <argument data> CR LF
	 *     ...
	 *     $<number of bytes of argument N> CR LF
	 *     <argument data> CR LF
	 *
	 * More information regarding the Redis protocol: http://redis.io/topics/protocol
	 *
	 * @param  string  $method
	 * @param  array   $parameters
	 * @return string
	 */
	public function buildCommand($method, array $parameters)
	{
		$command = '*'.(count($parameters) + 1)."\r\n";

		// Before each parameter, we must send the number of bytes in the upcoming
		// value that we are sending. So, we'll just take the sting length of a
		// parameter and add it to the command. Then we'll add the parameter.
		$command .= '$'.strlen($method)."\r\n";

		$command .= strtoupper($method)."\r\n";

		foreach ($parameters as $parameter)
		{
			$command .= '$'.strlen($parameter)."\r\n".$parameter."\r\n";
		}

		return $command;
	}

	/**
	 * Parse the Redis database response.
	 *
	 * @param  string  $response
	 * @return mixed
	 */
	public function parseResponse($response)
	{
		switch (substr($response, 0, 1))
		{
			// The first character of the response tells us what type of response we
			// are dealing with. So we will process the response according to the
			// the type of response we've received back from the Redis command.
			case '+':
				return $this->parseInlineResponse($response);

			case ':':
				return (int) $this->parseInlineResponse($response);

			case '$':
				return $this->parseBulkResponse($response);

			// "Multi-bulk" responses are used to handle responses that contain many
			// values such as the response for a "lrange" command to the database
			// and these will be handled similarly to regular "bulk" responses.
			case '*':
				return $this->parseMultiResponse($response);
		}

		throw new CommandException(trim($response));
	}

	/**
	 * Parse an inline response from the databsae.
	 *
	 * @param  string  $response
	 * @return string
	 */
	protected function parseInlineResponse($response)
	{
		return substr(trim($response), 1);
	}

	/**
	 * Parse a bulk response from the database.
	 *
	 * @param  string  $response
	 * @return string
	 */
	protected function parseBulkResponse($response)
	{
		// If the response size is listed as a negative one it means that there is
		// no data for the given keys, and we should return "null" according to
		// the Redis protocol documentation for every client Redis libraries.
		if ($response == '$-1')
		{
			return null;
		}

		$total = substr($response, 1);

		list($read, $data) = array(0, '');

		// If we have bytes to read, we will read off the data in 1024 byte chunks
		// and then return the response. Once we've read the data, we will also
		// need to read the final two byte new line feed off the file stream.
		if ($total > 0)
		{
			do
			{
				$data .= $this->readBulkBlock($total, $read);

			} while ($read < $total);
		}

		// After every response there is a final two byte new line feed that we'll
		// need to read off this stream to get it out of the way for subsequent
		// command responses that we may retrieve from the Redis connections.
		$this->fileRead(2);

		return $data;
	}
<commit_msg>Fixed an issue whereby the response check was failing due to additional space/newline character. Have added a trim to ensure the check is sane.<commit_after><?php namespace Illuminate\Redis;

class Database {

	/**
	 * The host address of the database.
	 *
	 * @var string
	 */
	protected $host;

	/**
	 * The port of the database.
	 *
	 * @var int
	 */
	protected $port;

	/**
	 * The database number to be selected.
	 *
	 * @var int
	 */
	protected $database;

	/**
	 * The Redis connection handler.
	 *
	 * @var resource
	 */
	protected $connection;

	/**
	 * Create a new Redis connection instance.
	 *
	 * @param  string  $host
	 * @param  int     $port
	 * @param  int     $database
	 * @return void
	 */
	public function __construct($host, $port, $database = 0)
	{
		$this->host = $host;
		$this->port = $port;
		$this->database = $database;
	}

	/**
	 * Connect to the Redis database.
	 *
	 * @return void
	 */
	public function connect()
	{
		if ( ! is_null($this->connection)) return;

		$this->connection = $this->openSocket();

		$this->command('select', array($this->database));
	}

	/**
	 * Run a command against the Redis database.
	 *
	 * @param  string  $method
	 * @param  array   $parameters
	 * @return mixed
	 */
	public function command($method, array $parameters = array())
	{
		$this->fileWrite($this->buildCommand($method, $parameters));

		return $this->parseResponse($this->fileGet(512));
	}

	/**
	 * Build the Redis command syntax.
	 *
	 * Redis protocol states that a command should conform to the following format:
	 *
	 *     *<number of arguments> CR LF
	 *     $<number of bytes of argument 1> CR LF
	 *     <argument data> CR LF
	 *     ...
	 *     $<number of bytes of argument N> CR LF
	 *     <argument data> CR LF
	 *
	 * More information regarding the Redis protocol: http://redis.io/topics/protocol
	 *
	 * @param  string  $method
	 * @param  array   $parameters
	 * @return string
	 */
	public function buildCommand($method, array $parameters)
	{
		$command = '*'.(count($parameters) + 1)."\r\n";

		// Before each parameter, we must send the number of bytes in the upcoming
		// value that we are sending. So, we'll just take the sting length of a
		// parameter and add it to the command. Then we'll add the parameter.
		$command .= '$'.strlen($method)."\r\n";

		$command .= strtoupper($method)."\r\n";

		foreach ($parameters as $parameter)
		{
			$command .= '$'.strlen($parameter)."\r\n".$parameter."\r\n";
		}

		return $command;
	}

	/**
	 * Parse the Redis database response.
	 *
	 * @param  string  $response
	 * @return mixed
	 */
	public function parseResponse($response)
	{
		switch (substr($response, 0, 1))
		{
			// The first character of the response tells us what type of response we
			// are dealing with. So we will process the response according to the
			// the type of response we've received back from the Redis command.
			case '+':
				return $this->parseInlineResponse($response);

			case ':':
				return (int) $this->parseInlineResponse($response);

			case '$':
				return $this->parseBulkResponse($response);

			// "Multi-bulk" responses are used to handle responses that contain many
			// values such as the response for a "lrange" command to the database
			// and these will be handled similarly to regular "bulk" responses.
			case '*':
				return $this->parseMultiResponse($response);
		}

		throw new CommandException(trim($response));
	}

	/**
	 * Parse an inline response from the databsae.
	 *
	 * @param  string  $response
	 * @return string
	 */
	protected function parseInlineResponse($response)
	{
		return substr(trim($response), 1);
	}

	/**
	 * Parse a bulk response from the database.
	 *
	 * @param  string  $response
	 * @return string
	 */
	protected function parseBulkResponse($response)
	{
		// If the response size is listed as a negative one it means that there is
		// no data for the given keys, and we should return "null" according to
		// the Redis protocol documentation for every client Redis libraries.
		if (trim($response) == '$-1')
		{
			return null;
		}

		$total = substr($response, 1);

		list($read, $data) = array(0, '');

		// If we have bytes to read, we will read off the data in 1024 byte chunks
		// and then return the response. Once we've read the data, we will also
		// need to read the final two byte new line feed off the file stream.
		if ($total > 0)
		{
			do
			{
				$data .= $this->readBulkBlock($total, $read);

			} while ($read < $total);
		}

		// After every response there is a final two byte new line feed that we'll
		// need to read off this stream to get it out of the way for subsequent
		// command responses that we may retrieve from the Redis connections.
		$this->fileRead(2);

		return $data;
	}

{'fraction_non_alphanumeric': 0.1262561471028437, 'fraction_numerical': 0.003848620910840282, 'mean_word_length': 2.9158643784010048, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2743268', 'n_tokens_mistral': 3139, 'n_tokens_neox': 2732, 'n_words': 1043}