Nestjs <> Redis Unable to connect to redis using private network url
aercwarden
PROOP

2 years ago

Unable to connect my nestjs server to redis using the private network url

  • added 5s sleep before start and build commands

  • both run in v2 runtime

  • nestjs server runs on ipv6 using ::

47 Replies

aercwarden
PROOP

2 years ago

9820d186-43b6-43fb-bdaf-7203f784ca8a/


aercwarden
PROOP

2 years ago

1273345398513078300


aercwarden
PROOP

2 years ago

CacheModule.registerAsync({
      isGlobal: true,
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: (configService: ConfigService) => ({
        store: redisStore,
        url: configService.get('REDIS_URL'),
        password: configService.get('REDIS_PASSWORD'),
        username: configService.get('REDIS_USERNAME'),
        ttl: 5,
      }),
    }),

aercwarden
PROOP

2 years ago

"cache-manager-redis-store": "2.0.0",

2 years ago

sleep is not needed with the v2 runtime, you can remove that


2 years ago

are you getting the error from build or runtime logs?


aercwarden
PROOP

2 years ago

runtime


2 years ago

i assume cache-manager-redis-store uses ioredis under the hood, if so, please read -


aercwarden
PROOP

2 years ago

just to be sure, i just concat the private url with familiy=0?


2 years ago

append ?family=0 yes


aercwarden
PROOP

2 years ago

will try and update here


aercwarden
PROOP

2 years ago

Error: getaddrinfo ENOTFOUND redis-awln.railway.internal at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:107:26)  ELIFECYCLE  Command failed with exit code 1.


aercwarden
PROOP

2 years ago

redis://[username]:[password]@redis-awln.railway.internal:6379?family=0


2 years ago

redis does not have a private domain of redis-awln.railway.internal in the linked project

1273348624293822500


2 years ago

please only ever use reference variables -

that way you can avoid these kinds of mistakes


aercwarden
PROOP

2 years ago

oh i see, so this url is invalid?


aercwarden
PROOP

2 years ago

1273349186506719200


aercwarden
PROOP

2 years ago

had referenced it from here


2 years ago

are we looking at different projects?


2 years ago

this is a screenshot from your linked project


aercwarden
PROOP

2 years ago

Yeah


aercwarden
PROOP

2 years ago

copied id from browser


aercwarden
PROOP

2 years ago

under pr-47


2 years ago

okay i wasnt told this was pr-47


aercwarden
PROOP

2 years ago

sorry, my bad


aercwarden
PROOP

2 years ago

thought the project id linked to pr


2 years ago

fair assumption


2 years ago

try settings family: 0, in the same config that you set the username


aercwarden
PROOP

2 years ago

just pushed, building now


2 years ago

lets see the updated code?


aercwarden
PROOP

2 years ago

CacheModule.registerAsync({
      isGlobal: true,
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: (configService: ConfigService) => ({
        family: 0,
        store: redisStore,
        url: configService.get('REDIS_URL'),
        password: configService.get('REDIS_PASSWORD'),
        username: configService.get('REDIS_USERNAME'),
        ttl: 5,
      }),
    }),

2 years ago

is this using ioredis under the hood?


aercwarden
PROOP

2 years ago

yup


aercwarden
PROOP

2 years ago

    dependencies:
      ioredis: 4.28.5

in lock file


aercwarden
PROOP

2 years ago

no its not


aercwarden
PROOP

2 years ago

"redisStore" is from this


2 years ago

i saw your other messages, it said ioredis


aercwarden
PROOP

2 years ago

unused library


aercwarden
PROOP

2 years ago

replaced by this


aercwarden
PROOP

2 years ago

"cache-manager": "^4",
"cache-manager-redis-store": "2.0.0",

only these are relevant libraries for using redis


aercwarden
PROOP

2 years ago

the cache manager redis store package is outdated, but i remember vaguely that we have it that since certain feature with nestjs was not working but let me try updating it to experiment


2 years ago

the version of redis that cache-manager-redis-store v2.0.0 uses is from 2021, likely didnt have support for ipv6 back then, so please upgrade cache-manager-redis-store to the latest version


aercwarden
PROOP

2 years ago

will try and let you know


aercwarden
PROOP

2 years ago

@Brody did not see any errors and server didnt crash
Can i keep this thread up till I confirm by testing a few stuff around the server


2 years ago

of course


aercwarden
PROOP

2 years ago

All seems good brod-a


2 years ago

great!


Loading...