R
Railway6mo ago
diay

Redis failing to connect with `ECONNREFUSED`

Hi team, today our apps started getting the error when trying to connect with our redis instance:
{"code":"ECONNREFUSED","error":"connect ECONNREFUSED 127.0.0.1:6379","errorLevel":"standard","label":"WorkerClientRedis","name":"Error","stack":"Error: connect ECONNREFUSED 127.0.0.1:6379\n at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1495:16)"}
{"code":"ECONNREFUSED","error":"connect ECONNREFUSED 127.0.0.1:6379","errorLevel":"standard","label":"WorkerClientRedis","name":"Error","stack":"Error: connect ECONNREFUSED 127.0.0.1:6379\n at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1495:16)"}
We've read through a couple threads and tried the following: 1. We are using private redis, so we've ensured we have family=0 set on the connections 2. We tried switching to the public connection. We're able to connect and run on app with the public connection locally, but we still get errors in prod. We're using ioredis with the following settings:
const BASE_REDIS_OPTIONS: RedisOptions = {
reconnectOnError: () => true,
connectTimeout: 5000,
retryStrategy: (times) => Math.min(times * 50, 2000),
maxRetriesPerRequest: 0,
enableReadyCheck: true,
autoResubscribe: true,
keepAlive: 1000 * 30,
family: 0,
const BASE_REDIS_OPTIONS: RedisOptions = {
reconnectOnError: () => true,
connectTimeout: 5000,
retryStrategy: (times) => Math.min(times * 50, 2000),
maxRetriesPerRequest: 0,
enableReadyCheck: true,
autoResubscribe: true,
keepAlive: 1000 * 30,
family: 0,
This was working for us until today
Solution:
yea ioredis 's Redis class claims that it can be constructed by passing an object with the connection options as follows: ```ts import Redis from 'ioredis' ...
Jump to solution
7 Replies
Percy
Percy6mo ago
Project ID: d5830106-c562-4490-bfe0-6636a0c4a844
diay
diayOP6mo ago
d5830106-c562-4490-bfe0-6636a0c4a844
Brody
Brody6mo ago
ECONNREFUSED 127.0.0.1:6379 the redis client is trying to connect to what would be its default options, please make sure you have the client config setup correctly
diay
diayOP6mo ago
Thanks we found and resolved the issue
Brody
Brody6mo ago
awsome, do you mind sharing it?
Solution
diay
diay6mo ago
yea ioredis 's Redis class claims that it can be constructed by passing an object with the connection options as follows:
import Redis from 'ioredis'

const new Redis({
path: ...,
port: ...,
host: ...,
...otherRedisOptions
})
import Redis from 'ioredis'

const new Redis({
path: ...,
port: ...,
host: ...,
...otherRedisOptions
})
Or by passing the connection url as follows:
import Redis from 'ioredis'

const new Redis(REDIS_URL, {
...otherRedisOptions
})
import Redis from 'ioredis'

const new Redis(REDIS_URL, {
...otherRedisOptions
})
We had recently switched to the first approach and that seemed to have broke things. Switching back to the second syntax did the trick
Brody
Brody6mo ago
perfect, thanks for the explanation!
Want results from more Discord servers?
Add your server