'use strict';

var redis = require('redis');

function _newRedisClient(port, server) {
  port = port || process.env.REDIS_PORT;
  server = server || process.env.REDIS_URL;

  var client = redis.createClient(process.env.REDISCLOUD_URL);

  client.once('ready', function() {
    console.log('Redis is connected');
  });

  // client.on('error', function (err) {
  //   console.log('Redis error:', err);
  // });

  client.on('reconnecting', function() {
    console.log('Redis is reconnecting');
  });

  client.once('end', function() {
    console.log('Redis connection terminated');
  });

  return client;
}

module.exports = {
  client: _newRedisClient(),
  sub: _newRedisClient()
};
@@ -37,16 +37,42 @@
 redis');
+%0Avar url = require('url');
 %0A%0Afuncti
@@ -100,80 +100,86 @@
 rt, 
-server) %7B%0A  port = port %7C%7C process.env.REDIS_PORT;%0A  server = server %7C%7C 
+host) %7B%0A  var client;%0A%0A  if (process.env.REDIS_URL) %7B%0A    var rtg = url.parse(
 proc
@@ -199,16 +199,13 @@
 _URL
-;%0A%0A  var
+)%0A   
  cli
@@ -233,36 +233,131 @@
 ent(
-process.env.REDISCLOUD_URL);
+rtg.port, rtg.hostname)%0A%0A    client.auth(rtg.auth.split(':')%5B1%5D)%0A  %7D else %7B%0A    client = redis.createClient(port, host)%0A  %7D
 %0A%0A  
@@ -437,19 +437,16 @@
   %7D);%0A%0A 
- //
  client.
@@ -465,17 +465,16 @@
 function
- 
 (err) %7B%0A
@@ -474,19 +474,16 @@
 err) %7B%0A 
- //
    conso
@@ -516,11 +516,8 @@
 );%0A 
- //
  %7D);

update redis conf