4

I am using node-redis and having a hard time connecting to external redis instance. I tried with redis-cli and it worked. However with node I am not able to figure out how to properly give the url and port.

With Redis-cli-

redis-cli -h mydomain.something.something.cache.amazonaws.com -p 6379

However with nodejs

Below didn't work

var client = redis.createClient('redis://mydomain.something.something.cache.amazonaws.com:6379'),

neither

var client = redis.createClient({host:'redis://mydomain.something.something.cache.amazonaws.com', port: 6379});

How do I configure it. Please help.

asked Mar 15, 2017 at 18:33
9
  • Your second code example looks correct. Are you running the node app on the same server that you tested connecting with redis-cli? Commented Mar 15, 2017 at 18:47
  • Yes. Is there any other way also to give this parameters? Commented Mar 15, 2017 at 18:48
  • You could try redis.createClient(6379, 'mydomain.something.something.cache.amazonaws.com') but I don't think it's going to make a difference. Are you getting any error messages when you test the node app? Commented Mar 15, 2017 at 18:49
  • Wait, will post that too. Have to look for logs. Commented Mar 15, 2017 at 18:56
  • 2
    Have you checked your security groups on AWS to make sure that servers have access to connect to Redis. It might also be worth pointing out that you are not able to connect to your Redis instances from outside of AWS network. docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/… Commented Apr 15, 2017 at 13:05

2 Answers 2

4

Following should work with node.js -

var client = require('redis').createClient(6379, 'elastichache endpoint string', {
 no_ready_check: true
 });

Also, make sure that your security group on AWS allows you to access the database.

aaronR
1,5672 gold badges18 silver badges26 bronze badges
answered Dec 1, 2017 at 21:27
Sign up to request clarification or add additional context in comments.

Comments

1
var client = require('redis').createClient(6379, 'elastichache endpoint string', {
 no_ready_check: true
 });

With the above code, it was always trying to connect with localhost,

Below code worked for me.

var client = require('redis').createClient(
 {
 url: `redis://${elasticCacheConnectionString}`,
 }
);

Please note, i have appended redis:// as communication protocol before actual connection string.

FYI: I am using [email protected] version.

answered Jul 18, 2022 at 7:15

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.