<commit_before>from redis.sentinel import StrictRedis, Sentinel
from src.settings import (REDIS_KEY_TTL, DBAAS_SENTINEL_ENDPOINT_SIMPLE,
                          DBAAS_SENTINEL_SERVICE_NAME, DBAAS_SENTINEL_PASSWORD)


class Persistence(object):

    def __init__(self):
        #hosts_sentinel = DBAAS_SENTINEL_ENDPOINT_SIMPLE.replace("sentinel://", "")
        #sentinels = list(map(lambda sentinel: tuple(sentinel.split(':')), hosts_sentinel.split(',')))
        #sentinel = Sentinel(sentinels, socket_timeout=1)
        #self.client = sentinel.master_for(DBAAS_SENTINEL_SERVICE_NAME, socket_timeout=1,
        # password=<PASSWORD>)
        self.client = StrictRedis()
        self.ttl_seconds = REDIS_KEY_TTL

    def was_notified(self, task):
        return self.client.exists(task.id)

    def set_notified(self, task):
        self.client.set(task.id, task.__dict__, self.ttl_seconds)

    def set_channel(self, channel_id, relevance_id):
        self.client.set(relevance_id, channel_id)

    def unset_channel(self, relevance_id):
        self.client.delete(relevance_id)

<commit_msg>Adding methods to get channel according relevance<commit_after>from redis.sentinel import StrictRedis, Sentinel
from src.settings import (REDIS_KEY_TTL, DBAAS_SENTINEL_ENDPOINT_SIMPLE,
                          DBAAS_SENTINEL_SERVICE_NAME, DBAAS_SENTINEL_PASSWORD)


class Persistence(object):

    def __init__(self):
        hosts_sentinel = DBAAS_SENTINEL_ENDPOINT_SIMPLE.replace("sentinel://", "")
        sentinels = list(map(lambda sentinel: tuple(sentinel.split(':')), hosts_sentinel.split(',')))
        sentinel = Sentinel(sentinels, socket_timeout=1)
        self.client = sentinel.master_for(DBAAS_SENTINEL_SERVICE_NAME, socket_timeout=1,
        password=<PASSWORD>)
        self.ttl_seconds = REDIS_KEY_TTL

    def was_notified(self, task):
        return self.client.exists(task.id)

    def set_notified(self, task):
        self.client.set(task.id, task.__dict__, self.ttl_seconds)

    def set_channel(self, channel_id, relevance_id):
        self.client.set(relevance_id, channel_id)

    def unset_channel(self, relevance_id):
        self.client.delete(relevance_id)

    def get_relevances_id(self, relevance):
        relevance_query = "{}_*".format(relevance)
        keys_list = self.client.keys(relevance_query)
        channels_list = []
        for key in keys_list:
            channels_list.append(self.client.get(key))
        return channels_list
{'fraction_non_alphanumeric': 0.10270926000808735, 'fraction_numerical': 0.0016174686615446825, 'mean_word_length': 3.667924528301887, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1974836', 'n_tokens_mistral': 868, 'n_tokens_neox': 820, 'n_words': 129}