var redis = require('redis');

function getConnection() {
  var db = redis.createClient();
  db.select(6, function (err) { if (err) throw err; });
  return db;
}

exports.redis = redis;
exports.getConnection = getConnection;

var redis = require('redis');

function throwError(err) {
  if (err) {
    throw err;
  }
}

function logError(err) {
  console.log(err);
}

function getConnection() {
  var port = process.env.REDIS_PORT || 6379,
      host = process.env.REDIS_HOST || '127.0.0.1',
      password = process.env.REDIS_PASS,
      dbNumber = process.env.REDIS_DB;
  var db = redis.createClient(port, host);
  db.on('error', logError);

  var callback = throwError;
  if (dbNumber) {
    callback = function() { db.select(dbNumber, throwError); };
  }

  if (password) {
    db.auth(password, callback);
  } else {
    callback();
  }
  return db;
}

exports.redis = redis;
exports.getConnection = getConnection;

Make redis helper production-ready