<commit_before><?php

namespace Plume\Provider;

use redis as redisClient;

class RedisProvider extends Provider{

    private $instance = null;

    private $instance_slave = null;

    public function connectSlave(){
        if($this->instance_slave instanceof redisClient){
            return $this->$instance_slave;
        }
        $this->instance_slave = $this->instance_slave ?: new RedisClient();
        $config = $this->getConfig();
        $config = isset($config['redis_slave']) ? $config['redis_slave'] : $config;
        $host = isset($config['host']) ? $config['host'] : '127.0.0.1';
        $port = isset($config['port']) ? (int) $config['port'] : '6379';
        $password = isset($config['password']) ? $config['password'] : '';
        $database = isset($config['database']) ? $config['database'] : '0';
        $timeout = isset($config['timeout']) ? $config['timeout'] : '0';
        if (!$this->instance_slave->connect($host, (int) $port, (int) $timeout)) {
                throw new \Exception('redis connection Failed');
        }
        if ($password && !$this->instance_slave->auth($password)) {
                throw new \Exception('redis password is wrong!');
        }
        if ($database) {
            $this->instance_slave->select((int) $database);
        }
        return $this->instance_slave;

    }

    public function connect(){
        if($this->instance instanceof redisClient){
            return $this->instance;
        }
        $this->instance = $this->instance ?: new RedisClient();
        $config = $this->getConfig();
        $config = isset($config['redis']) ? $config['redis'] : $config;
        $host = isset($config['host']) ? $config['host'] : '127.0.0.1';
        $port = isset($config['port']) ? (int) $config['port'] : '6379';
        $password = isset($config['password']) ? $config['password'] : '';
        $database = isset($config['database']) ? $config['database'] : '0';
        $timeout = isset($config['timeout']) ? $config['timeout'] : '0';
        if (!$this->instance->connect($host, (int) $port, (int) $timeout)) {
                throw new \Exception('redis connection Failed');
        }
        if ($password && !$this->instance->auth($password)) {
                throw new \Exception('redis password is wrong!');
        }
        if ($database) {
            $this->instance->select((int) $database);
        }
        return $this->instance;
    }

    public function close(){
        if($this->instance instanceof redisClient){
            $this->instance->close();
        }
    }

    public function closeSlave(){
        if($this->instance_slave instanceof redisClient){
            $this->instance_slave->close();
        }
    }

}<commit_msg>fix redis provider close bug reconnect bug<commit_after><?php

namespace Plume\Provider;

use redis as redisClient;

class RedisProvider extends Provider{

    private $instance = null;

    private $instance_slave = null;

    public function connectSlave(){
        if($this->instance_slave instanceof redisClient){
            return $this->$instance_slave;
        }
        $this->instance_slave = $this->instance_slave ?: new RedisClient();
        $config = $this->getConfig();
        $config = isset($config['redis_slave']) ? $config['redis_slave'] : $config;
        $host = isset($config['host']) ? $config['host'] : '127.0.0.1';
        $port = isset($config['port']) ? (int) $config['port'] : '6379';
        $password = isset($config['password']) ? $config['password'] : '';
        $database = isset($config['database']) ? $config['database'] : '0';
        $timeout = isset($config['timeout']) ? $config['timeout'] : '0';
        if (!$this->instance_slave->connect($host, (int) $port, (int) $timeout)) {
                throw new \Exception('redis connection Failed');
        }
        if ($password && !$this->instance_slave->auth($password)) {
                throw new \Exception('redis password is wrong!');
        }
        if ($database) {
            $this->instance_slave->select((int) $database);
        }
        return $this->instance_slave;

    }

    public function connect(){
        if($this->instance instanceof redisClient){
            return $this->instance;
        }
        $this->instance = $this->instance ?: new RedisClient();
        $config = $this->getConfig();
        $config = isset($config['redis']) ? $config['redis'] : $config;
        $host = isset($config['host']) ? $config['host'] : '127.0.0.1';
        $port = isset($config['port']) ? (int) $config['port'] : '6379';
        $password = isset($config['password']) ? $config['password'] : '';
        $database = isset($config['database']) ? $config['database'] : '0';
        $timeout = isset($config['timeout']) ? $config['timeout'] : '0';
        if (!$this->instance->connect($host, (int) $port, (int) $timeout)) {
                throw new \Exception('redis connection Failed');
        }
        if ($password && !$this->instance->auth($password)) {
                throw new \Exception('redis password is wrong!');
        }
        if ($database) {
            $this->instance->select((int) $database);
        }
        return $this->instance;
    }

    public function close(){
        if($this->instance instanceof redisClient){
            $this->instance->close();
            $this->instance = null;
        }
    }

    public function closeSlave(){
        if($this->instance_slave instanceof redisClient){
            $this->instance_slave->close();
            $this->instance_slave = null;
        }
    }

}
{'fraction_non_alphanumeric': 0.18165499910249505, 'fraction_numerical': 0.008616047388260635, 'mean_word_length': 2.5786769428387926, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, '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': '2215979', 'n_tokens_mistral': 1589, 'n_tokens_neox': 1573, 'n_words': 328}