<commit_before>import redis

""" Cache is a set with information already seen by the system.
    This provides a way, for example, to remove duplicated events
    and reports in system or cache some results from experts like
    Cymru Whois. It's possible to define a TTL value in each information
    inserted in cache. This TTL means how much time the system will keep an 
    information in the cache.
"""

class Cache():
    def __init__(self, host, port, db, ttl):
        self.redis = redis.Redis(host = host,
                                 port = int(port),
                                 db = db,
                                 socket_timeout = 5)
        
        self.ttl = ttl


    def exists(self, key):
        return self.redis.exists(key)

    def get(self, key):
        return self.redis.get(key)

    def set(self, key, value):
        # backward compatibility (Redis v2.2)
        self.redis.setnx(key, value)
        self.redis.expire(key, self.ttl)<commit_msg>Add docstrings to lib/cache.py and pep8 mods<commit_after>import redis

""" Cache is a set with information already seen by the system.
    This provides a way, for example, to remove duplicated events
    and reports in system or cache some results from experts like
    Cymru Whois. It's possible to define a TTL value in each information
    inserted in cache. This TTL means how much time the system will keep an
    information in the cache.
"""


class Cache():
    def __init__(self, host, port, db, ttl):
        self.redis = redis.Redis(host=host,
                                 port=int(port),
                                 db=db,
                                 socket_timeout=5)

        self.ttl = ttl

    def exists(self, key):
        """Returns True if key exists in the cache"""
        return self.redis.exists(key)

    def get(self, key):
        """Returns the value of key in cache"""
        return self.redis.get(key)

    def set(self, key, value):
        """Sets key to value in cache"""
        # backward compatibility (Redis v2.2)
        self.redis.setnx(key, value)
        self.redis.expire(key, self.ttl)
{'fraction_non_alphanumeric': 0.08251289263947492, 'fraction_numerical': 0.0032817627754336614, 'mean_word_length': 2.0014064697609, '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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6918750', 'n_tokens_mistral': 605, 'n_tokens_neox': 590, 'n_words': 232}