<commit_before><commit_msg>Dynamic Redis module for `redis-py` & `redis-py-cluster` support.<commit_after># pytask
# File: pytask/redis_util.py
# Desc: pytask Redis normalisation

from redis import StrictRedis
from redis.exceptions import ConnectionError

# We always have Redis
redis_clients = [StrictRedis]
redis_errors = [ConnectionError]

try:
    # Get optional cluster
    from rediscluster import StrictRedisCluster
    from rediscluster.exceptions import ClusterDownException

    redis_clients.append(StrictRedisCluster)
    redis_errors.append(ClusterDownException)

except ImportError:
    StrictRedisCluster = None

# For isinstance and exception capturing
redis_clients = tuple(redis_clients)
redis_errors = tuple(redis_errors)


def make_redis(args):
    '''
    Makes a ``RedisCluster`` or ``Redis`` instance (when list/dict, not instance, is
    passed to ``PyTask.__init__``.
    '''

    if StrictRedisCluster:
        return StrictRedisCluster(args, decode_responses=True)
    else:
        return StrictRedis(**args)

{'fraction_non_alphanumeric': 0.08196721311475409, 'fraction_numerical': 0.0, 'mean_word_length': 4.734806629834254, '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': '2601214', 'n_tokens_mistral': 333, 'n_tokens_neox': 326, 'n_words': 81}