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.

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.

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.

Comments

Your Answer

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.