Ioredis Node connection issue.
    const redisConnection: RedisOptions = {
      host: `http://${process.env.REDIS_HOST}`,
      port: Number(process.env.REDIS_PORT),
      password: process.env.REDIS_PASS,
      username: process.env.REDIS_USER,
      family: 0,
      retryStrategy: (times) => {
        // reconnect after
        return Math.min(times * 50, 2000);
      },
    };

My connection object above

[ioredis] Unhandled error event: Error: getaddrinfo ENOTFOUND http://redis-cache-staging.railway.internal

Solved

38 Replies

13314144-b328-475d-867f-a0337164519f


I have set the family as you can see


i also have sleep 3 in my start command


brody
EMPLOYEE

2 years ago

nixpacks or dockerfile?


nixpacks with the sleep command in the package.json start command


brody
EMPLOYEE

2 years ago

according to the redis service settings, is that host correct?


redis-cache-staging.railway.internal

Should i have the http infront ?


brody
EMPLOYEE

2 years ago

redis does not use http


kkk let me check. should i justhave

redis-cache-staging.railway.internal


brody
EMPLOYEE

2 years ago

is the redis database in the same environment as the service thats trying to connect to it



brody
EMPLOYEE

2 years ago

are you sure the sleep 3 is being ran?



brody
EMPLOYEE

2 years ago

how so?



i have removed http:// and redeploying now to check


[ioredis] Unhandled error event: Error: connect ECONNREFUSED 127.0.0.1:6379
at _nodeinternal_captureLargerStackTrace (node:internal/errors:496:5)
at _nodeinternal_exceptionWithHostPort (node:internal/errors:671:12)
at TCPConnectWrap.afterConnect as oncomplete


    const redisConnection: RedisOptions = {
      host: process.env.REDIS_HOST,
      port: Number(process.env.REDIS_PORT),
      password: process.env.REDIS_PASS,
      username: process.env.REDIS_USER,
      family: 0,
      retryStrategy: (times) => {
        // reconnect after
        return Math.min(times * 50, 2000);
      },
    };

Host is set correctly in the variables


brody
EMPLOYEE

2 years ago

you are still using shared variables


brody
EMPLOYEE

2 years ago

please see this for ioredis



i have applied everything from the railway docs


brody
EMPLOYEE

2 years ago

please stop using shared variables for this


brody
EMPLOYEE

2 years ago

use reference variables


ok changed from shared variables, using reference vars from redis service


Redis port has gone blank on the redis service


brody
EMPLOYEE

2 years ago

use the private url variable please


brody
EMPLOYEE

2 years ago

just like the example in the docs shows


Ok using the private url string only works. But i wonder why you cannot construct using the options with all the same details


brody
EMPLOYEE

2 years ago

probably just configured it wrong


@Brody thanks for all the help man. appreciate it


brody
EMPLOYEE

2 years ago

no problem


tech
HOBBY

2 years ago

Hi sorry to bring this back up, but I'm not able to see the messages on discord, and I think many links are missing here.

What is the right solution to get a redis instance running within the same project? I'm having issues with the host being undefined.

"just like the example in the docs shows" does anyone have links to these docs please?


brody
EMPLOYEE

2 years ago

No worries, the links are indeed missing.

Getting ioredis setup correctly with private networking checklist -

Example -

const redis = new Redis(process.env.REDIS_URL + "?family=0");

michael88
PRO

a year ago

Hi, I'm still having this exact issue.

I'm running:
ioredis 5.5.0
node 22.8.0

I'm configuring the redis instance like this:
```

const redisClient = new Redis(`${process.env.REDIS_URL}?family=0`, {
    tls: { rejectUnauthorized: false },
    lazyConnect: true,
    connectTimeout: 15000,
    retryStrategy: (times) => Math.min(times * 30, 1000),
  });

```

My redis url looks like this when I print it out: redis://default:yyBqSILlgwiYDnZOPgvQELaUAmvKLjgc@redis.railway.internal:6379

I'm using setting the REDIS_URL variable like this on railway: ${{Redis.REDIS_URL}}

Also regarding @brody's checklist, "ensure V2 runtime enabled" - I cannot see such on option on either my redis-service or my backend-service config. Is there another way to configure this?

One thing to note is that my redis service is deployed in a US region while the backend is in europe. Ofc I'd want them both in Europe but its currently not an option on the hobby plan.

Thanks in advance!


michael88

Hi, I'm still having this exact issue.I'm running:ioredis 5.5.0node 22.8.0I'm configuring the redis instance like this:```const redisClient = new Redis(`${process.env.REDIS_URL}?family=0`, { tls: { rejectUnauthorized: false }, lazyConnect: true, connectTimeout: 15000, retryStrategy: (times) => Math.min(times * 30, 1000), });```My redis url looks like this when I print it out: redis://default:yyBqSILlgwiYDnZOPgvQELaUAmvKLjgc@redis.railway.internal:6379I'm using setting the REDIS_URL variable like this on railway: ${{Redis.REDIS_URL}}Also regarding @brody's checklist, "ensure V2 runtime enabled" - I cannot see such on option on either my redis-service or my backend-service config. Is there another way to configure this?One thing to note is that my redis service is deployed in a US region while the backend is in europe. Ofc I'd want them both in Europe but its currently not an option on the hobby plan.Thanks in advance!

brody
EMPLOYEE

a year ago

Can you please open your own help thread, a new thread would be preferable over an 8 month old thread.


brody
EMPLOYEE

a year ago

!s


Loading...