title: How to instantiate Multiple Redis Connections for Publish Subscribe (node.js + node_redis)
body: <h2>Scenario</h2>
  
  <p>Using <strong>node_redis</strong> to build a simple Redis Pubish Subscribe (chat) example: <a href="https://github.com/nelsonic/hapi-socketio-redis-chat-example" rel="nofollow noreferrer">https://github.com/nelsonic/hapi-socketio-redis-chat-example</a> (<em>with Hapi.js and Socket.io</em>)</p>
  
  <p>We have created a node module <strong>redis_connection.js</strong> in our project ( see: <a href="http://git.io/vqaos" rel="nofollow noreferrer">http://git.io/vqaos</a> ) to instantiate the Redis connection because we don't want to be <em>repeating</em> the code which connects (to RedisCloud) multiple times:</p>
  
  <pre><code>var redis = require('redis');
  var url   = require('url');
  var redisURL    = url.parse(process.env.REDISCLOUD_URL);
  var redisClient = redis.createClient(redisURL.port, redisURL.hostname,
                    {no_ready_check: true});
  redisClient.auth(redisURL.auth.split(":")[1]);
  
  module.exports = redisClient;
  </code></pre>
  
  <p>Which we then <em>use</em> like this:</p>
  
  <pre><code>var redisClient = require('./redis_connection.js');
  
  // Confirm we are able to connect to  RedisCloud:
  redisClient.set('redis', 'working', redisClient.print);
  redisClient.get('redis', function (err, reply) {
    console.log('RedisCLOUD is ' +reply.toString());
  });
  </code></pre>
  
  <p>This works fine for normal GET/SET operations with Redis,
  but when we try to instantiate multiple connections to Redis (e.g: one to publish, another to subscribe and a third just to GET/SET keys/values) we get an error:</p>
  
  <h2>Issue</h2>
  
  <p>We are seeing the following error:</p>
  
  <p><code>Error: Connection in subscriber mode, only subscriber commands may be used</code></p>
  
  <p>What are we doing wrong?</p>
  
  <p>Full code at the point where we see this issue: <a href="http://git.io/vqa6y" rel="nofollow noreferrer">http://git.io/vqa6y</a></p>
  
  <h3>Note</h3>
  
  <p>We <em>tried</em> to dig through existing SO Q/A on this, e.g:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/5140398/publish-subscribe-with-nodejs-and-redisnode-redis">Publish subscribe with nodejs and redis(node_redis)</a></li>
  <li><a href="https://stackoverflow.com/questions/10952837/redis-publish-subscribe-see-what-channels-are-currently-subscribed-to">Redis publish/subscribe: see what channels are currently subscribed to</a></li>
  <li><a href="https://stackoverflow.com/questions/19453463/how-to-use-the-redis-publish-subscribe">how to use the redis publish/subscribe</a></li>
  </ul>
  
  <p>but did not find a solution that <em>exactly</em> matched our situation...</p>
  
  <p>(<em>any suggestions/help much appreciated!</em>)</p>