<commit_before>from .client import RedisClient

import json
import redis
import sys


class RedisPool:
    """
    """
    _shared_state = {}

    def __init__(self):
        self.__dict__ = self._shared_state

    def ping(self, db='DEFAULT'):
        return self.connections[db].ping()

    def set_json(self, k, v, db='DEFAULT'):
        jval = json.dumps(v)
        self.set(k, jval)

    def set(self, k, v, db='DEFAULT'):
        self.connections[db].set(k, v)

    def delete(self, k, db='DEFAULT'):
        self.connections[db].delete(k)

    def get_json(self, k, db='DEFAULT', encode='utf-8'):
        val = self.get(k, db=db)
        if val is not None:
            return json.loads(val.decode(encode))
        else:
            return {}

    def get(self, k, db='DEFAULT'):
        return self.connections[db].get(k)

    def close(self, db=None):
        if db is None:
            for k, v in self.connections.items():
                v.close()
            self.connections = {}
        else:
            v = self.connections[db]
            v.close()
            del self.connections[db]

    def flushall(self):
        for k, v in self.connections.items():
            v.flushdb()


redis_pool = RedisPool()
redis_pool.connections = {}


def get_pool():
    return redis_pool


def init_db_conn(connection_name, HOST=None, PORT=None, DB=None):
    """
    Initialize a redis connection by each connection string
    defined in the configuration file
    """
    rpool = redis.ConnectionPool(host=HOST, port=PORT, db=DB)
    r = redis.Redis(connection_pool=rpool)
    redis_pool.connections[connection_name] = RedisClient(r)


def initialize(g, app):
    """
    If redis connection parameters are defined in configuration params a
    session will be created
    """

    if 'DATABASES' in app.config and 'REDIS' in app.config['DATABASES']:

        # Initialize connections for console commands
        for k, v in app.config['DATABASES']['REDIS'].items():
            init_db_conn(k, **v)

        @app.before_request<commit_msg>add password to init_db_conn method<commit_after>from .client import RedisClient

import json
import redis
import sys


class RedisPool:
    """
    """
    _shared_state = {}

    def __init__(self):
        self.__dict__ = self._shared_state

    def ping(self, db='DEFAULT'):
        return self.connections[db].ping()

    def set_json(self, k, v, db='DEFAULT'):
        jval = json.dumps(v)
        self.set(k, jval)

    def set(self, k, v, db='DEFAULT'):
        self.connections[db].set(k, v)

    def delete(self, k, db='DEFAULT'):
        self.connections[db].delete(k)

    def get_json(self, k, db='DEFAULT', encode='utf-8'):
        val = self.get(k, db=db)
        if val is not None:
            return json.loads(val.decode(encode))
        else:
            return {}

    def get(self, k, db='DEFAULT'):
        return self.connections[db].get(k)

    def close(self, db=None):
        if db is None:
            for k, v in self.connections.items():
                v.close()
            self.connections = {}
        else:
            v = self.connections[db]
            v.close()
            del self.connections[db]

    def flushall(self):
        for k, v in self.connections.items():
            v.flushdb()


redis_pool = RedisPool()
redis_pool.connections = {}


def get_pool():
    return redis_pool


def init_db_conn(connection_name, HOST=None, PORT=None, DB=None, PASSWORD=None):
    """
    Initialize a redis connection by each connection string
    defined in the configuration file
    """
    rpool = redis.ConnectionPool(host=HOST, port=PORT, db=DB, password=PASSWORD)
    r = redis.Redis(connection_pool=rpool)
    redis_pool.connections[connection_name] = RedisClient(r)


def initialize(g, app):
    """
    If redis connection parameters are defined in configuration params a
    session will be created
    """

    if 'DATABASES' in app.config and 'REDIS' in app.config['DATABASES']:

        # Initialize connections for console commands
        for k, v in app.config['DATABASES']['REDIS'].items():
            init_db_conn(k, **v)

        @app.before_request
{'fraction_non_alphanumeric': 0.12271414821944177, 'fraction_numerical': 0.00048123195380173246, 'mean_word_length': 2.4612822647793506, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '907803', 'n_tokens_mistral': 1342, 'n_tokens_neox': 1285, 'n_words': 335}