<commit_before>from constance import settings, utils
from constance.backends import Backend

try:
    from cPickle import loads, dumps
except ImportError:
    from pickle import loads, dumps


class RedisBackend(Backend):

    def __init__(self):
        super(RedisBackend, self).__init__()
        self._prefix = settings.PREFIX
        connection_cls = settings.CONNECTION_CLASS
        if connection_cls is not None:
            self._rd = utils.import_module_attr(connection_cls)()
        else:
            import redis
            self._rd = redis.Redis(**settings.REDIS_CONNECTION)

    def get(self, key):
        value = self._rd.get("%s%s" % (self._prefix, key))
        if value:
            return loads(value)
        return None

    def set(self, key, value):
        self._rd.set("%s%s" % (self._prefix, key), dumps(value))<commit_msg>Raise an ImproperlyConfigured exception if the Redis backend is used (default) and redis-py can't be found.<commit_after>from django.core.exceptions import ImproperlyConfigured

from constance import settings, utils
from constance.backends import Backend

try:
    from cPickle import loads, dumps
except ImportError:
    from pickle import loads, dumps


class RedisBackend(Backend):

    def __init__(self):
        super(RedisBackend, self).__init__()
        self._prefix = settings.PREFIX
        connection_cls = settings.CONNECTION_CLASS
        if connection_cls is not None:
            self._rd = utils.import_module_attr(connection_cls)()
        else:
            try:
                import redis
            except ImportError:
                raise ImproperlyConfigured(
                    "The Redis backend requires redis-py to be installed.")
            self._rd = redis.Redis(**settings.REDIS_CONNECTION)

    def get(self, key):
        value = self._rd.get("%s%s" % (self._prefix, key))
        if value:
            return loads(value)
        return None

    def set(self, key, value):
        self._rd.set("%s%s" % (self._prefix, key), dumps(value))
{'fraction_non_alphanumeric': 0.09122287968441814, 'fraction_numerical': 0.0, 'mean_word_length': 2.5596491228070177, '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': '3799574', 'n_tokens_mistral': 590, 'n_tokens_neox': 583, 'n_words': 161}