<commit_before>import logging
import redis
import urlparse
import dill as pickle

from will import settings


class StorageMixin(object):
    def bootstrap_storage(self):
        # redis://localhost:6379/7
        # or
        # redis://rediscloud:asdfkjaslkdjflasdf@pub-redis-12345.us-east-1-1.2.ec2.garantiadata.com:12345
        url = urlparse.urlparse(settings.WILL_REDIS_URL)

        if hasattr(url, "path"):
            db = url.path[1:]
        else:
            db = 0

        self.storage = redis.StrictRedis(host=url.hostname, port=url.port, db=db, password=url.password)

    def save(self, key, value):
        if not hasattr(self, "storage"):
            self.bootstrap_storage()
        try:
            return self.storage.set(key, pickle.dumps(value))
        except:
            logging.warn("Unable to save %s" % key)

    def clear(self, key):
        if not hasattr(self, "storage"):
            self.bootstrap_storage()
        return self.storage.delete(key)

    def clear_all_keys(self):<commit_msg>right. debug. sorry for spam.<commit_after>import logging
import redis
import urlparse
import dill as pickle

from will import settings


class StorageMixin(object):
    def bootstrap_storage(self):
        # redis://localhost:6379/7
        # or
        # redis://rediscloud:asdfkjaslkdjflasdf@pub-redis-12345.us-east-1-1.2.ec2.garantiadata.com:12345
        url = urlparse.urlparse(settings.WILL_REDIS_URL)

        if hasattr(url, "path"):
            db = url.path[1:]
        else:
            db = 0

        self.storage = redis.StrictRedis(host=url.hostname, port=url.port, db=db, password=url.password)

    def save(self, key, value):
        if not hasattr(self, "storage"):
            self.bootstrap_storage()
        print "saving %s...." % key
        print self.storage
        try:
            ret = self.storage.set(key, pickle.dumps(value))
            print ret
            print self.storage.get(key)
            return ret
        except:
            logging.warn("Unable to save %s" % key)

    def clear(self, key):
        if not hasattr(self, "storage"):
            self.bootstrap_storage()
        return self.storage.delete(key)

    def clear_all_keys(self):
{'fraction_non_alphanumeric': 0.11342069588793494, 'fraction_numerical': 0.018978761861726163, 'mean_word_length': 2.28, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '2189876', 'n_tokens_mistral': 732, 'n_tokens_neox': 694, 'n_words': 149}