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

aercwarden
PRO

a year 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 ::

0 Replies

aercwarden
PRO

a year ago

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


aercwarden
PRO

a year ago

1273345398513078300


aercwarden
PRO

a year 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
PRO

a year ago

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

a year ago

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


a year ago

are you getting the error from build or runtime logs?


aercwarden
PRO

a year ago

runtime


a year ago

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


aercwarden
PRO

a year ago

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


a year ago

append ?family=0 yes


aercwarden
PRO

a year ago

will try and update here


aercwarden
PRO

a year 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
PRO

a year ago

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


a year ago

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

1273348624293822500


a year ago

please only ever use reference variables -

that way you can avoid these kinds of mistakes


aercwarden
PRO

a year ago

oh i see, so this url is invalid?


aercwarden
PRO

a year ago

1273349186506719200


aercwarden
PRO

a year ago

had referenced it from here


a year ago

are we looking at different projects?


a year ago

this is a screenshot from your linked project


aercwarden
PRO

a year ago

Yeah


aercwarden
PRO

a year ago

copied id from browser


aercwarden
PRO

a year ago

under pr-47


a year ago

okay i wasnt told this was pr-47


aercwarden
PRO

a year ago

sorry, my bad


aercwarden
PRO

a year ago

thought the project id linked to pr


a year ago

fair assumption


a year ago

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


aercwarden
PRO

a year ago

just pushed, building now


a year ago

lets see the updated code?


aercwarden
PRO

a year 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,
      }),
    }),

a year ago

is this using ioredis under the hood?


aercwarden
PRO

a year ago

yup


aercwarden
PRO

a year ago

    dependencies:
      ioredis: 4.28.5

in lock file


aercwarden
PRO

a year ago

no its not


aercwarden
PRO

a year ago

"redisStore" is from this


a year ago

i saw your other messages, it said ioredis


aercwarden
PRO

a year ago

unused library


aercwarden
PRO

a year ago

replaced by this


aercwarden
PRO

a year ago

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

only these are relevant libraries for using redis


aercwarden
PRO

a year 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


a year 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
PRO

a year ago

will try and let you know


aercwarden
PRO

a year 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


a year ago

of course


aercwarden
PRO

a year ago

All seems good brod-a


a year ago

great!