title: Connecting to an Azure Redis Cluster using node.js ioredis not working
body: <p>I've been trying to connect to a Redis three node cluster in Azure using <a href="https://github.com/luin/ioredis" rel="nofollow noreferrer">ioredis</a>.</p>
  
  <p>When I connect using the Redis.Cluster constructor:</p>
  
  <pre><code>new Redis.Cluster(['host.redis.cache.windows.net', 6380], {
      scaleReads: 'all',
      slotsRefreshTimeout: 2000,
      redisOptions: {
          password: 'some-secret',
          tls: true as any
      },
  });
  </code></pre>
  
  <p>The error I get is:</p>
  
  <pre><code>2020-06-04T13:05:41.787Z ioredis:cluster getting slot cache from 127.0.0.1:6380
  2020-06-04T13:05:41.788Z ioredis:redis status[127.0.0.1:6380 (ioredisClusterRefresher)]: [empty] -&gt; wait
  2020-06-04T13:05:41.788Z ioredis:redis status[127.0.0.1:6380 (ioredisClusterRefresher)]: wait -&gt; connecting
  2020-06-04T13:05:41.788Z ioredis:redis queue command[127.0.0.1:6380 (ioredisClusterRefresher)]: 0 -&gt; cluster([ 'slots' ])
  2020-06-04T13:05:41.790Z ioredis:connection error: Error: connect ECONNREFUSED 127.0.0.1:6380
  2020-06-04T13:05:41.791Z ioredis:redis status[127.0.0.1:6380 (ioredisClusterRefresher)]: connecting -&gt; close
  2020-06-04T13:05:41.791Z ioredis:connection skip reconnecting because `retryStrategy` is not a function
  2020-06-04T13:05:41.791Z ioredis:redis status[127.0.0.1:6380 (ioredisClusterRefresher)]: close -&gt; end
  2020-06-04T13:05:41.792Z [auth-middleware] Redis error { ClusterAllFailedError: Failed to refresh slots cache.
      at tryNode (/app/node_modules/ioredis/built/cluster/index.js:359:31)
      at /app/node_modules/ioredis/built/cluster/index.js:376:21
      at duplicatedConnection.cluster.utils_2.timeout (/app/node_modules/ioredis/built/cluster/index.js:624:24)
      at run (/app/node_modules/ioredis/built/utils/index.js:156:22)
      at tryCatcher (/app/node_modules/standard-as-callback/built/utils.js:11:23)
      at promise.then (/app/node_modules/standard-as-callback/built/index.js:30:51)
      at process._tickCallback (internal/process/next_tick.js:68:7)
    lastNodeError:
     Error: Connection is closed.
         at close (/app/node_modules/ioredis/built/redis/event_handler.js:179:25)
         at TLSSocket.&lt;anonymous&gt; (/app/node_modules/ioredis/built/redis/event_handler.js:150:20)
         at Object.onceWrapper (events.js:277:13)
         at TLSSocket.emit (events.js:194:15)
         at _handle.close (net.js:600:12)
         at TCP.done (_tls_wrap.js:388:7) }
  </code></pre>
  
  <p>When I connect using a non-cluster Redis connection:</p>
  
  <pre><code>new Redis(6380, 'host.redis.cache.windows.net', { password: 'some-secret' });
  </code></pre>
  
  <p>The error I get is:</p>
  
  <pre><code>020-06-04T15:04:08.609Z ioredis:redis status[10.211.x.x:6380]: connecting -&gt; connect
  2020-06-04T15:04:08.614Z ioredis:redis write command[10.211.x.x:6380]: 0 -&gt; auth([ 'some-secret' ])
  2020-06-04T15:04:08.616Z ioredis:redis write command[10.211.x.x:6380]: 0 -&gt; info([])
  2020-06-04T15:05:16.114Z ioredis:connection error: Error: read ECONNRESET
  2020-06-04T15:05:16.115Z [auth-middleware] Redis error { Error: read ECONNRESET
      at TCP.onStreamRead (internal/stream_base_commons.js:111:27) errno: 'ECONNRESET', code: 'ECONNRESET', syscall: 'read' }
  </code></pre>
  
  <p>As you can see it is using TLS on port 6380. Azure provides me with one host+port combination and two different access-keys (primary/seconday) - which I find weird, which access-key should I use? Also I'm not sure if I should be connecting in Cluster mode, but I'd prefer to to gain the benefits of clustering. When I do it appears it tries to find the slots at <code>127.0.0.1:6380</code> which is probably not correct.</p>
  
  <p>In Azure's <a href="https://docs.microsoft.com/en-us/azure/azure-cache-for-redis/cache-nodejs-get-started" rel="nofollow noreferrer">quickstart</a> they connect using node_redis with:</p>
  
  <pre><code>var redis = require("redis");
  
  // Add your cache name and access key.
  var client = redis.createClient(6380, process.env.REDISCACHEHOSTNAME,
      {auth_pass: process.env.REDISCACHEKEY, tls: {servername: process.env.REDISCACHEHOSTNAME}});
  </code></pre>
  
  <p>I was hoping someone here would have come across the same issue and solved it.</p>
  
  <p>Thanks!</p>