Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connect AWS redis to node using node-redis

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.

like image 610
scripter Avatar asked Oct 18 '25 08:10

scripter


2 Answers

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.

like image 95
Apoorv Purwar Avatar answered Oct 20 '25 00:10

Apoorv Purwar


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.

like image 34
Mahendra Patel Avatar answered Oct 20 '25 00:10

Mahendra Patel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!