R
Railway8mo ago
joao

node redis

any hacks to connect to redis on node? ive slept the 5s but still conn refused
Solution:
after just looking at the docs, you are using the library incorrectly, please read the docs https://www.npmjs.com/package/redis#usage...
Jump to solution
23 Replies
Percy
Percy8mo ago
Project ID: N/A
joao
joao8mo ago
N/A
Brody
Brody8mo ago
please show the error. are you trying to connect to the database via public or private networking? what library are you using? anything else you think may be useful information
joao
joao8mo ago
i'm using the official node-redis client and conecting via private networking rn im just doing sleep 5 && runcommand lol
Brody
Brody8mo ago
please show the error
joao
joao8mo ago
Error: connect ECONNREFUSED ::1:6379
Brody
Brody8mo ago
show the code that initialises the connection please
joao
joao8mo ago
redisClient = await createClient()
.on("error", (err) => console.log("redis client err:", err))
.on("connect", () => {
console.log("redis conn successful");
app.listen(PORT, () =>
console.log(
`server started on port ${PORT}`
)
);
})
.connect({ url: REDIS_URL });
redisClient = await createClient()
.on("error", (err) => console.log("redis client err:", err))
.on("connect", () => {
console.log("redis conn successful");
app.listen(PORT, () =>
console.log(
`server started on port ${PORT}`
)
);
})
.connect({ url: REDIS_URL });
Brody
Brody8mo ago
have you confirmed that REDIS_URL is the correct value
joao
joao8mo ago
yes its an env var which i set in the dashboard imma try via public netwk
Brody
Brody8mo ago
from this error, it looks like it's trying to connect to localhost, and port 6379, Which is the default when you don't supply the correct information to the connect constructor
joao
joao8mo ago
nope not it yeah i know because of the ipv6 loopback addr lol i checked that but the env var is set
Brody
Brody8mo ago
that's not it, you're thinking of something that's doesn't apply here please confirm your code is seeing the proper redis url can you also show me how you have set the REDIS_URL in code
joao
joao8mo ago
yes the app has access to the variable the REDIS_URL is the value from destructuring process.env
Brody
Brody8mo ago
have you printed that variable to confirm it's correct value?
joao
joao8mo ago
yup
Brody
Brody8mo ago
okay i will try to reproduce
Solution
Brody
Brody8mo ago
after just looking at the docs, you are using the library incorrectly, please read the docs https://www.npmjs.com/package/redis#usage
joao
joao8mo ago
what do you mean wrong
Brody
Brody8mo ago
please read the docs
joao
joao8mo ago
youre right yea now it makes sense sorry abt that it was defaulting to localhost because i wasnt passing the url in the right method
Brody
Brody8mo ago
correct
joao
joao8mo ago
thanks! and sorry for such a stupid mistake