<commit_before># -*- test-case-name: vumi.persist.tests.test_redis_manager -*-

import redis

from vumi.persist.redis_base import Manager


class RedisManager(Manager):
    @classmethod
    def from_config(cls, config, key_prefix=''):
        """Construct a manager from a dictionary of options.

        :param dict config:
            Dictionary of options for the manager.
        :param str key_prefix:
            Key prefix for namespacing.
        """

        # FIXME: Handle fake redis better.
        from vumi.tests.utils import FakeRedis
        if config == "FAKE_REDIS":
            return cls(FakeRedis(), key_prefix)
        if isinstance(config, FakeRedis):
            return cls(config, key_prefix)

        config = config.copy()  # So we can safely mutilate it.

        config_prefix = config.pop('key_prefix', None)
        if config_prefix is not None:
            key_prefix = "%s:%s" % (config_prefix, key_prefix)

        return cls(redis.StrictRedis(**config), key_prefix)

    def _close(self):
        """Close redis connection."""
        pass

    def _purge_all(self):
        """Delete *ALL* keys whose names start with this manager's key prefix.

        Use only in tests.
        """
        for key in self.keys():
            self.delete(key)

    def _make_redis_call(self, call, *args, **kw):
        """Make a redis API call using the underlying client library.
        """
        return getattr(self._client, call)(*args, **kw)

    def _filter_redis_results(self, func, results):
        """Filter results of a redis call.
        """
        return func(results)<commit_msg>Use redis.Redis instead of redis.StrictRedis.<commit_after># -*- test-case-name: vumi.persist.tests.test_redis_manager -*-

import redis

from vumi.persist.redis_base import Manager


class RedisManager(Manager):
    @classmethod
    def from_config(cls, config, key_prefix=''):
        """Construct a manager from a dictionary of options.

        :param dict config:
            Dictionary of options for the manager.
        :param str key_prefix:
            Key prefix for namespacing.
        """

        # FIXME: Handle fake redis better.
        from vumi.tests.utils import FakeRedis
        if config == "FAKE_REDIS":
            return cls(FakeRedis(), key_prefix)
        if isinstance(config, FakeRedis):
            return cls(config, key_prefix)

        config = config.copy()  # So we can safely mutilate it.

        config_prefix = config.pop('key_prefix', None)
        if config_prefix is not None:
            key_prefix = "%s:%s" % (config_prefix, key_prefix)

        return cls(redis.Redis(**config), key_prefix)

    def _close(self):
        """Close redis connection."""
        pass

    def _purge_all(self):
        """Delete *ALL* keys whose names start with this manager's key prefix.

        Use only in tests.
        """
        for key in self.keys():
            self.delete(key)

    def _make_redis_call(self, call, *args, **kw):
        """Make a redis API call using the underlying client library.
        """
        return getattr(self._client, call)(*args, **kw)

    def _filter_redis_results(self, func, results):
        """Filter results of a redis call.
        """
        return func(results)
{'fraction_non_alphanumeric': 0.10379669320269443, 'fraction_numerical': 0.0, 'mean_word_length': 2.3268839103869654, 'pattern_counts': {'":': 2, '<': 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': '1981232', 'n_tokens_mistral': 955, 'n_tokens_neox': 933, 'n_words': 289}