var urllib = require('url');

var redis = require('redis');

require('es6-promise').polyfill();  // Polyfill `Promise`.


var db = {};

db.redis = {};


const REDIS_URL = process.env.REDIS_URL || process.env.REDISTOGO_URL;

if (REDIS_URL) {
  var rtg = urllib.parse(REDIS_URL);
  db.redis.client = redis.createClient(rtg.port, rtg.hostname);
  db.redis.client.auth(rtg.auth.split(':')[1]);
} else {
  db.redis.client = redis.createClient();
}

db.redis.set = function (key, value, cb) {
  return new Promise(function (resolve, reject) {
    db.redis.client.set(key, value, function (err, reply) {
      if (err) {
        reject(err);
      } else {
        resolve(reply);
      }
    });
  });
};

db.redis.get = function (key, cb) {
  return new Promise(function (resolve, reject) {
    db.redis.client.get(key, function (err, reply) {
      if (err) {
        reject(err);
      } else {
        resolve(reply);
      }
    });
  });
};

db.redis.remove = function (key, cb) {
  return new Promise(function (resolve, reject) {
    db.redis.client.del(key, function (err, reply) {
      if (err) {
        reject(err);
      } else {
        resolve(reply);
      }
    });
  });
};


module.exports = db;

@@ -214,16 +214,46 @@
 TOGO_URL
+ %7C%7C process.env.REDISCLOUD_URL
 ;%0A%0Aif (R

support Redis Cloud