<commit_before><?php
/**
 * Wrap Credis to add namespace support and various helper methods.
 *
 * @package		Resque/Redis
 * @author		<NAME> <<EMAIL>>
 * @license		http://www.opensource.org/licenses/mit-license.php
 */
class Resque_Redis
{
    /**
     * Redis namespace
     * @var string
     */
    private static $defaultNamespace = 'resque:';

    private $server;
    private $database;

	/**
	 * @var array List of all commands in Redis that supply a key as their
	 *	first argument. Used to prefix keys with the Resque namespace.
	 */
	private $keyCommands = array(
		'exists',
		'del',
		'type',
		'keys',
		'expire',
		'ttl',
		'move',
		'set',
		'setex',
		'get',
		'getset',
		'setnx',
		'incr',
		'incrby',
		'decr',
		'decrby',
		'rpush',
		'lpush',
		'llen',
		'lrange',
		'ltrim',
		'lindex',
		'lset',
		'lrem',
		'lpop',
		'rpop',
		'sadd',
		'srem',
		'spop',
		'scard',
		'sismember',
		'smembers',
		'srandmember',
		'zadd',
		'zrem',
		'zrange',
		'zrevrange',
		'zrangebyscore',
		'zcard',
		'zscore',
		'zremrangebyscore',
		'sort'
	);
	// sinterstore
	// sunion
	// sunionstore
	// sdiff
	// sdiffstore
	// sinter
	// smove
	// rename
	// rpoplpush
	// mget
	// msetnx
	// mset
	// renamenx

	/**
	 * Set Redis namespace (prefix) default: resque
	 * @param string $namespace
	 */
	public static function prefix($namespace)
	{
	    if (strpos($namespace, ':') === false) {
	        $namespace .= ':';
	    }
	    self::$defaultNamespace = $namespace;
	}

	public function __construct($server, $database = null)
	{
		$this->server = $server;
		$this->database = $database;

		if (is_array($this->server)) {
			$this->driver = new Credis_Cluster($server);
		}
		else {
			$port = null;
			$host = $server;

			// If not a UNIX socket path or tcp:// formatted connections string
			// assume host:port combination.
			if (strpos($server, '/') === false) {
				$parts = explode(':', $server);
				if (isset($parts[1])) {
					$port = $parts[1];
				}
				$host = $parts[0];
			}
			$this->driver = new Credis_Client($host, $port);
		}

		if ($this->database !== null) {
			$this->driver->select($database);
		}<commit_msg>adding support for remote redis instances (such as redistogo) that require authentication<commit_after><?php
/**
 * Wrap Credis to add namespace support and various helper methods.
 *
 * @package		Resque/Redis
 * @author		<NAME> <<EMAIL>>
 * @license		http://www.opensource.org/licenses/mit-license.php
 */
class Resque_Redis
{
    /**
     * Redis namespace
     * @var string
     */
    private static $defaultNamespace = 'resque:';

    private $server;
    private $database;

	/**
	 * @var array List of all commands in Redis that supply a key as their
	 *	first argument. Used to prefix keys with the Resque namespace.
	 */
	private $keyCommands = array(
		'exists',
		'del',
		'type',
		'keys',
		'expire',
		'ttl',
		'move',
		'set',
		'setex',
		'get',
		'getset',
		'setnx',
		'incr',
		'incrby',
		'decr',
		'decrby',
		'rpush',
		'lpush',
		'llen',
		'lrange',
		'ltrim',
		'lindex',
		'lset',
		'lrem',
		'lpop',
		'rpop',
		'sadd',
		'srem',
		'spop',
		'scard',
		'sismember',
		'smembers',
		'srandmember',
		'zadd',
		'zrem',
		'zrange',
		'zrevrange',
		'zrangebyscore',
		'zcard',
		'zscore',
		'zremrangebyscore',
		'sort'
	);
	// sinterstore
	// sunion
	// sunionstore
	// sdiff
	// sdiffstore
	// sinter
	// smove
	// rename
	// rpoplpush
	// mget
	// msetnx
	// mset
	// renamenx

	/**
	 * Set Redis namespace (prefix) default: resque
	 * @param string $namespace
	 */
	public static function prefix($namespace)
	{
	    if (strpos($namespace, ':') === false) {
	        $namespace .= ':';
	    }
	    self::$defaultNamespace = $namespace;
	}

	public function __construct($server, $database = null)
	{
		$this->server = $server;
		$this->database = $database;

		if (is_array($this->server)) {
			$this->driver = new Credis_Cluster($server);
		}
		else {
			$port = null;
			$password = null;
			$host = $server;

			// If not a UNIX socket path or tcp:// formatted connections string
			// assume host:port combination.
			if (strpos($server, '/') === false) {
				$parts = explode(':', $server);
				if (isset($parts[1])) {
					$port = $parts[1];
				}
				$host = $parts[0];
			}else if (strpos($server, 'redis://') !== false){
				// Redis format is:
				// redis://[user]:[password]@[host]:[port]
				list($userpwd,$hostport) = explode('@', $server);
				$userpwd = substr($userpwd, strpos($userpwd, 'redis://')+8);
				list($host, $port) = explode(':', $hostport);
				list($user, $password) = explode(':', $userpwd);
			}
			
			$this->driver = new Credis_Client($host, $port);
			if (isset($password)){
				$this->driver->auth($password);
			}
		}

		if ($this->database !== null) {
			$this->driver->select($database);
		}
{'fraction_non_alphanumeric': 0.1873697373905794, 'fraction_numerical': 0.0014589412255106293, 'mean_word_length': 2.8392, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5407640', 'n_tokens_mistral': 2029, 'n_tokens_neox': 1764, 'n_words': 412}