cache.js 768 B

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