Connect AWS redis to node using node-redis

scripter picture scripter · Mar 15, 2017 · Viewed 7.9k times · Source

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.

Answer

Apoorv Purwar picture Apoorv Purwar · Dec 1, 2017

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.