Can't connect to Redis
This is the error I am getting. What I have checked so far
* Made sure I used the env variables provided by Railway
* Exposed the REDISPORT in my dockerfile
Solution:Jump to solution
Looks like a library bug: https://github.com/redis/node-redis/issues/2416
GitHub
createClient trying to connect with localhost even though URL is fo...
Description I am trying to create a client with URL redis://${process.env.REDIS_HOST}:${process.env.REDIS_PORT}, and sending REDIS_HOST=rediss and REDIS_PORT=6379, but still it is trying to connect...
45 Replies
Project ID:
N/A
049b9d61-9cd8-4102-aad9-1350a56e2b7e
I saw this message, but unclear what the actionable item is here for my Dockerfile
send the dockerfile please
I believe that is correct?
okay so help me understand why you have redisport stuff?
I thought Docker was not exposing the port correctly and the one provided to me by Railway is different from the default, so I am accepting it via the env var and exposing it
you're connecting to redis, you don't need to expose anything
remove the ARG and EXPOSE stuff please
next, show me a screenshot of your service variables please
Removed the ARG and EXPOSE and still unable to connect
I know, we will work through this, have patience please
Oh I was just updating you since you were instructing me to remove the arg and expose. I wasn't trying to rush you. My apologies if it came off that way.
go ahead and add the rest of the redis reference variables now
Okay, I just finished doing that
screenshot please
Do I have to keep those env vars even if I am only referencing
REDIS_URL
in my application code?no, but I don't know what you reference in code so it was a safe bet to ask you to use them all
now show me the redis connector code please
what package are you using for redis
GitHub
GitHub - redis/node-redis: Redis Node.js client
Redis Node.js client. Contribute to redis/node-redis development by creating an account on GitHub.
what's the ! for
TypeScript thing to tell it the var will always be defined
fancy
yeah pretty useful
okay well it looks fine then
but your error comes from trying to connect to the default redis host and port, so your code isn't actually trying to connect to the url you have specified
Yeah, I suspect it might be a docker issue
no it's not, this is a code issue
share your repo and I'll have a look to see if anything stands out for me?
For what it's worth, I have it working locally with a redis url
I can share the file, but let me double check one thing
unfortunately "it works locally" does not rule out this being a code issue
Solution
Looks like a library bug: https://github.com/redis/node-redis/issues/2416
GitHub
createClient trying to connect with localhost even though URL is fo...
Description I am trying to create a client with URL redis://${process.env.REDIS_HOST}:${process.env.REDIS_PORT}, and sending REDIS_HOST=rediss and REDIS_PORT=6379, but still it is trying to connect...
Okay, I'll sort it out. I'll try explicit env vars of port, user, pass, etc...
see, it's a good thing I had you add them all!
foresight
and see, it's not a docker issue
Not a docker issue, but definitely relevant
I don't see how it is, but lol
y u being like this
naw but i think you're right though. I always think its docker related when i see errors related to 127.0.0.1
it's just a loopback address, really nothing to do with docker
@Brody guess what. It's docker relevant.
Wait going to share a repo with you. I think you are more knowledgable here and might be able to explain this better than I can.
@Brody Is it possible to rotate my REDIS username and password later? I am thinking to just hardcode it in the private repo for the brevity
chill with the pings please #🛂|readme #5
but yes you can rotate your redis credentials, and no you should not hardcode the credentials even for brevity
My apologies. I appreciate you letting me know.
just share your repo lol
again, it's not a docker issue, if this was, there would be a hell of a lot more people in here saying they can't connect to redis, since regardless of using a dockerfile or nixpacks, docker is used in the end
Ah nevermind. I was testing the repo then realized I made mistake in my earlier testing. I can't figure out the issue. Will try again in the morning!
However, it's clear its a library issue, so I don't want to use anymore of your time! Thank you for the help, as always!
no problem