Turn audio into a shareable video. forked from nypublicradio/audiogram

remote.js 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. var redis = require("redis"),
  2. queue = require("d3").queue;
  3. module.exports = function(host) {
  4. // Prefix all keys to avoid collisions
  5. var prefix = "audiogram:";
  6. var client = redis.createClient({ host: host, password: process.env.REDIS_PASSWORD });
  7. client.on("error", function(err) {
  8. throw err;
  9. });
  10. function hset(key, field, value) {
  11. client.hset(prefix + key, field, value);
  12. }
  13. function hgetall(key, cb) {
  14. client.hgetall(prefix + key, cb);
  15. }
  16. function hincr(key, field) {
  17. client.hincrby(prefix + key, field, 1);
  18. }
  19. function getJobList(cb) {
  20. client.lrange(prefix + "jobs", 0, -1, function(err, jobs) {
  21. if (!err && jobs) {
  22. jobs = jobs.map(function(job){
  23. return JSON.parse(job);
  24. });
  25. }
  26. cb(err,jobs);
  27. });
  28. }
  29. function addJob(settings) {
  30. client.rpush(prefix + "jobs", JSON.stringify(settings));
  31. }
  32. function getJob(cb) {
  33. client.blpop(prefix + "jobs", 5, function(err, job) {
  34. cb(err, job ? JSON.parse(job[1]) : null);
  35. });
  36. }
  37. function quit() {
  38. client.quit();
  39. }
  40. function clean(cb) {
  41. client.keys(prefix + "*", function(err, keys){
  42. if (err || !keys.length) {
  43. return cb(err);
  44. }
  45. client.del(keys, cb);
  46. });
  47. }
  48. return {
  49. setField: hset,
  50. getHash: hgetall,
  51. incrementField: hincr,
  52. getJobList: getJobList,
  53. addJob: addJob,
  54. getJob: getJob,
  55. quit: quit,
  56. cleanJobs: clean
  57. };
  58. };