<commit_before><?php 

namespace KingNet\PhpRedis;

use Closure;
use Illuminate\Support\Arr;
use Illuminate\Contracts\Redis\Database as DatabaseContracts;
use \Redis;
use \RedisArray;


class Database implements DatabaseContracts
{
    /**
     * The host address of the database.
     *
     * @var array
     */
    protected $clients;

    /**
     * Create a new Redis connection instance.
     *
     * @param  array  $servers
     * @return void
     */
    public function __construct(array $servers = [])
    {

        $options = (array) Arr::pull($servers, 'options');

        $this->clients = $this->createSingleClients($servers, $options);
    
    }

    /**
     * Create an array of single connection clients.
     *
     * @param  array  $servers
     * @param  array  $options
     * @return array
     */
    protected function createSingleClients(array $servers, array $options =[])
    {
        $clients = [];

        foreach ($servers as $key => $server) {
           
            $phpredis = new Redis();
            $host    = empty($server['host']) ? '127.0.0.1' : $server['host'];
            $port    = empty($server['port'])?'6379':$server['port']; 
            $timeout = empty($server['timeout'])?0:$server['timeout'];

            
            if (isset($server['persistent']) && $server['persistent']) {
                $phpredis->pconnect($host,$port,$timeout);
            } else {
                $phpredis->connection($host,$port,$timeout);
            }

            if (!empty($server['prefix']))
              {
                $phpredis->setOption(Redis::OPT_PREFIX,$server['prefix']);
              }

            //   redis的数据库默认是从0 - 16 
            if ((int)$server['database']>=0 && (int)$server['database']<=16)
            {
                $phpredis->select($server['database']);
            }

            if (!empty($server['serializer'])) 
            {
                $serializer = Redis::SERIALIZER_NONE;
                if ($server['serializer'] === 'php')
                {
                    $serializer = Redis::SERIALIZER_PHP;
                } 
                elseif ($server['serializer'] === 'igbinary') 
                {
                    if (defined('Redis::SERIALIZER_IGBINARY')) 
                    {
                        $serializer = Redis::SERIALIZER_IGBINARY;
                    } 
                    else 
                    {
                        $serializer = Redis::SERIALIZER_PHP;
                    }
                }
                $phpredis->setOption(Redis::OPT_SERIALIZER, $serializer);
            }

            $clients['$key'] = $phpredis;

        }

        return $clients;
    }

    /**
     * Get a specific Redis connection instance.
     *
     * @param  string  $name
     * @return \redis\ClientInterface|null
     */
    public function connection($name = 'default')
    {
        return Arr::get($this->clients, $name ?: 'default');
    }

    /**
     * Run a command against the Redis database.
     *
     * @param  string  $method
     * @param  array   $parameters
     * @return mixed
     */
    public function command($method, array $parameters = [])
    {
        return call_user_func_array([$this->clients['default'], $method], $parameters);
    }

    /**
     * Dynamically make a Redis command.
     *
     * @param  string  $method
     * @param  array   $parameters
     * @return mixed
     */
    public function __call($method, $parameters)
    {
        return $this->command($method, $parameters);
    }
}<commit_msg>更新一些bug<commit_after><?php 

namespace KingNet\PhpRedis;

use Closure;
use Illuminate\Support\Arr;
use Illuminate\Contracts\Redis\Database as DatabaseContracts;
use \Redis as Redis;


class Database implements DatabaseContracts
{
    /**
     * The host address of the database.
     *
     * @var array
     */
    protected $clients;

    /**
     * Create a new Redis connection instance.
     *
     * @param  array  $servers
     * @return void
     */
    public function __construct(array $servers = [])
    {

        $options = (array) Arr::pull($servers, 'options');

        $this->clients = $this->createSingleClients($servers, $options);
    
    }

    /**
     * Create an array of single connection clients.
     *
     * @param  array  $servers
     * @param  array  $options
     * @return array
     */
    protected function createSingleClients(array $servers, array $options =[])
    {
        $clients = [];

        foreach ($servers as $key => $server) {
           
            $phpredis = new Redis();
            $host    = empty($server['host']) ? '127.0.0.1' : $server['host'];
            $port    = empty($server['port'])?'6379':$server['port']; 
            $timeout = empty($server['timeout'])?0:$server['timeout'];

            
            if (isset($server['persistent']) && $server['persistent']) {
                $phpredis->pconnect($host,$port,$timeout);
            } else {
                $phpredis->connection($host,$port,$timeout);
            }

            if (!empty($server['prefix']))
              {
                $phpredis->setOption(Redis::OPT_PREFIX,$server['prefix']);
              }

            //   redis的数据库默认是从0 - 16 
            if ((int)$server['database']>=0 && (int)$server['database']<=16)
            {
                $phpredis->select($server['database']);
            }

            if (!empty($server['serializer'])) 
            {
                $serializer = Redis::SERIALIZER_NONE;
                if ($server['serializer'] === 'php')
                {
                    $serializer = Redis::SERIALIZER_PHP;
                } 
                elseif ($server['serializer'] === 'igbinary') 
                {
                    if (defined('Redis::SERIALIZER_IGBINARY')) 
                    {
                        $serializer = Redis::SERIALIZER_IGBINARY;
                    } 
                    else 
                    {
                        $serializer = Redis::SERIALIZER_PHP;
                    }
                }
                $phpredis->setOption(Redis::OPT_SERIALIZER, $serializer);
            }

            $clients[$key] = $phpredis;

        }

        return $clients;
    }

    /**
     * Get a specific Redis connection instance.
     *
     * @param  string  $name
     * @return \redis\ClientInterface|null
     */
    public function connection($name = 'default')
    {
        return Arr::get($this->clients, $name ?: 'default');
    }

    /**
     * Run a command against the Redis database.
     *
     * @param  string  $method
     * @param  array   $parameters
     * @return mixed
     */
    public function command($method, array $parameters = [])
    {
        return call_user_func_array([$this->clients['default'], $method], $parameters);
    }

    /**
     * Dynamically make a Redis command.
     *
     * @param  string  $method
     * @param  array   $parameters
     * @return mixed
     */
    public function __call($method, $parameters)
    {
        return $this->command($method, $parameters);
    }
}
{'fraction_non_alphanumeric': 0.13870876797293488, 'fraction_numerical': 0.004792782633211165, 'mean_word_length': 1.6513452914798206, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '7272941', 'n_tokens_mistral': 2069, 'n_tokens_neox': 1994, 'n_words': 384}