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

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 ::
Solution:
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
Jump to solution
30 Replies
Percy
Percy3mo ago
Project ID: 9820d186-43b6-43fb-bdaf-7203f784ca8a
0xArc ⚡
0xArc ⚡3mo ago
9820d186-43b6-43fb-bdaf-7203f784ca8a/
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,
}),
}),
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,
}),
}),
"cache-manager-redis-store": "2.0.0",
"cache-manager-redis-store": "2.0.0",
Brody
Brody3mo ago
sleep is not needed with the v2 runtime, you can remove that are you getting the error from build or runtime logs?
0xArc ⚡
0xArc ⚡3mo ago
runtime
Brody
Brody3mo ago
i assume cache-manager-redis-store uses ioredis under the hood, if so, please read - https://docs.railway.app/guides/private-networking#known-configuration-requirements-for-ipv6
0xArc ⚡
0xArc ⚡3mo ago
just to be sure, i just concat the private url with familiy=0?
Brody
Brody3mo ago
append ?family=0 yes
0xArc ⚡
0xArc ⚡3mo ago
will try and update here
Error: getaddrinfo ENOTFOUND redis-awln.railway.internal
at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:107:26)
 ELIFECYCLE  Command failed with exit code 1.
Error: getaddrinfo ENOTFOUND redis-awln.railway.internal
at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:107:26)
 ELIFECYCLE  Command failed with exit code 1.
redis://[username]:[password]@redis-awln.railway.internal:6379?family=0
Brody
Brody3mo ago
redis does not have a private domain of redis-awln.railway.internal in the linked project
No description
Brody
Brody3mo ago
please only ever use reference variables - https://docs.railway.app/guides/variables#referencing-another-services-variable that way you can avoid these kinds of mistakes
0xArc ⚡
0xArc ⚡3mo ago
oh i see, so this url is invalid?
0xArc ⚡
0xArc ⚡3mo ago
No description
0xArc ⚡
0xArc ⚡3mo ago
had referenced it from here
Brody
Brody3mo ago
are we looking at different projects? this is a screenshot from your linked project
0xArc ⚡
0xArc ⚡3mo ago
Yeah copied id from browser under pr-47
Brody
Brody3mo ago
okay i wasnt told this was pr-47
0xArc ⚡
0xArc ⚡3mo ago
sorry, my bad thought the project id linked to pr
Brody
Brody3mo ago
fair assumption try settings family: 0, in the same config that you set the username
0xArc ⚡
0xArc ⚡3mo ago
just pushed, building now
Brody
Brody3mo ago
lets see the updated code?
0xArc ⚡
0xArc ⚡3mo 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,
}),
}),
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,
}),
}),
Brody
Brody3mo ago
is this using ioredis under the hood?
0xArc ⚡
0xArc ⚡3mo ago
no its not "redisStore" is from this
Brody
Brody3mo ago
i saw your other messages, it said ioredis
0xArc ⚡
0xArc ⚡3mo ago
unused library replaced by this
"cache-manager": "^4",
"cache-manager-redis-store": "2.0.0",
"cache-manager": "^4",
"cache-manager-redis-store": "2.0.0",
only these are relevant libraries for using redis 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
Solution
Brody
Brody3mo 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
0xArc ⚡
0xArc ⚡3mo ago
will try and let you know @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
Brody
Brody3mo ago
of course
0xArc ⚡
0xArc ⚡3mo ago
All seems good brod-a
Brody
Brody3mo ago
great!
Want results from more Discord servers?
Add your server