2
0

cache.js 946 B

123456789101112131415161718192021222324252627282930313233
  1. var config = require("./config");
  2. var url = require('url');
  3. var redisURL = url.parse(process.env.REDISCLOUD_URL);
  4. var redis = require("redis").createClient(redisURL.port, redisURL.hostname, {no_ready_check: true});
  5. redis.auth(redisURL.auth.split(":")[1]);
  6. var exp = {};
  7. // sets the timestamp for +uuid+ to now
  8. exp.update_timestamp = function(uuid) {
  9. console.log(uuid + " cache: updating timestamp");
  10. var time = new Date().getTime();
  11. redis.hmset(uuid, "t", time);
  12. };
  13. // create the key +uuid+, store +hash+ and time
  14. exp.save_hash = function(uuid, hash) {
  15. console.log(uuid + " cache: saving hash");
  16. var time = new Date().getTime();
  17. redis.hmset(uuid, "h", hash, "t", time);
  18. };
  19. // get a details object for +uuid+
  20. // {hash: "0123456789abcdef", time: 1414881524512}
  21. // null when uuid unkown
  22. exp.get_details = function(uuid, callback) {
  23. redis.hgetall(uuid, function(err, data) {
  24. callback(err, data);
  25. });
  26. };
  27. module.exports = exp;