<commit_before>var config = require("./config");
var redis = require("redis").createClient();

var exp = {};

// sets the timestamp for +uuid+ to now
exp.update_timestamp = function(uuid) {
  console.log(uuid + " cache: updating timestamp");
  var time = new Date().getTime();
  redis.hmset(uuid, "t", time);
};

// create the key +uuid+, store +hash+ and time
exp.save_hash = function(uuid, hash) {
  console.log(uuid + " cache: saving hash");
  var time = new Date().getTime();
  redis.hmset(uuid, "h", hash, "t", time);
};

// get a details object for +uuid+
// {hash: "0123456789abcdef", time: 1414881524512}
// null when uuid unkown
exp.get_details = function(uuid, callback) {
  redis.hgetall(uuid, function(err, data) {
    callback(err, data);
  });
};

module.exports = exp;<commit_msg>add support for heroku redis, catch errors, more logging, auto reconnect<commit_after>var config = require("./config");
var redis = null;


function connect_redis() {
  console.log("connecting to redis");
  if (process.env.REDISTOGO_URL) {
    var rtg   = require("url").parse(process.env.REDISTOGO_URL);
    redis = require("redis").createClient(rtg.port, rtg.hostname);
    redis.auth(rtg.auth.split(":")[1]);
  } else {
    redis = require("redis").createClient();
  }
  redis.on("ready", function() {
    console.log("Redis connection established.");
  });
  redis.on("error", function (err) {
    console.error(err);
  });
  redis.on("end", function () {
    console.warn("Redis connection lost!");
  });
}

var exp = {};

// sets the timestamp for +uuid+ to now
exp.update_timestamp = function(uuid) {
  console.log(uuid + " cache: updating timestamp");
  var time = new Date().getTime();
  redis.hmset(uuid, "t", time);
};

// create the key +uuid+, store +hash+ and time
exp.save_hash = function(uuid, hash) {
  console.log(uuid + " cache: saving hash");
  var time = new Date().getTime();
  redis.hmset(uuid, "h", hash, "t", time);
};

// get a details object for +uuid+
// {hash: "0123456789abcdef", time: 1414881524512}
// null when uuid unkown
exp.get_details = function(uuid, callback) {
  redis.hgetall(uuid, function(err, data) {
    callback(err, data);
  });
};

connect_redis();
module.exports = exp;
{'fraction_non_alphanumeric': 0.17758698599186626, 'fraction_numerical': 0.021238138273836422, 'mean_word_length': 4.125, 'pattern_counts': {'":': 1, '<': 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': '181966', 'n_tokens_mistral': 793, 'n_tokens_neox': 765, 'n_words': 193}