By using AWS re:Post, you agree to the Terms of Use

Unable to connect to redis cluster with node client, what am I doing wrong?


I have spun up an AWS ElastiCache redis instance running in clustered mode, which currently has 1 shard and 2 nodes

In order to connect to it from my local machine I have opened up an SSH tunnel using my SSH config file

Host myRedisTunnel
  LocalForward 6378

the tunnel works, I can connect to my VPC successfully

$ ssh myRedisTunnel
Welcome to Ubuntu 18.04.6 LTS (GNU/Linux 5.4.0-1060-aws x86_64)

I can connect to the redis cluster locally via redis-cli after opening my tunnel and passing -c as an argument for clustered mode

$ redis-cli -c -h localhost -p 6378
localhost:6378> ping

but when I try to use redis for nodejs it wont connect, it just times out, am i missing some configuration settings, or is it physically impossible to connect to my remote redis via tunnel?

const { createCluster } = require('redis')

const client = createCluster({
  rootNodes: [
    { url: 'redis://localhost:6378' }

await client.connect()
const res = await
console.log({ res })
Error: Connection timeout
      at Socket.<anonymous> (node_modules/@node-redis/client/dist/lib/client/socket.js:163:124)
      at Object.onceWrapper (node:events:513:28)
      at Socket.emit (node:events:394:28)
      at Socket._onTimeout (node:net:486:8)
      at listOnTimeout (node:internal/timers:557:17)
      at processTimers (node:internal/timers:500:7)

I have tried several nodejs clients for redis and all of them have timed out in the same way, so I know the issue has to either be that I have a config setting wrong in my nodejs redis client configuration - or it has something to do with only one of the redis ip addresses is accessible via tunnel, all the rest of the cluster would likely not be accessible unless i open tunnels for each one. Im just at a loss for how mock my production environment in development so i can write code.

asked 9 months ago64 views
No Answers

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions