scripter
scripter

Reputation: 1526

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.

Upvotes: 4

Views: 14636

Answers (2)

Mahendra Patel
Mahendra Patel

Reputation: 116

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.

Upvotes: 1

Apoorv Purwar
Apoorv Purwar

Reputation: 41

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.

Upvotes: 4

Related Questions