Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (19.1k points)

We know that ElastiCache is not recommended to be accessed outside Amazon instances, so we're trying below stuff inside Amazon EC2 instances only.

We've got an ElastiCache Redis Cluster with 9 nodes. When we try to connect to it using normal redis implementation, it throws some Moved errors

None of these implementations is working. Any suggestions, please?

1 Answer

+1 vote
by (44.4k points)

This code will work:

var RedisClustr = require('redis-clustr');

var RedisClient = require('redis');

var config = require("./config.json");

var redis = new RedisClustr({

    servers: [

        {

            host: config.redisClusterHost,

            port: config.redisClusterPort

        }

    ],

    createClient: function (port, host) {

        // this is the default behaviour

        return RedisClient.createClient(port, host);

    }

});

//connect to redis

redis.on("connect", function () {

  console.log("connected");

});

//check the functioning

redis.set("framework", "AngularJS", function (err, reply) {

  console.log("redis.set " , reply);

});

redis.get("framework", function (err, reply) {

  console.log("redis.get ", reply);

});

In this tutorial on AWS EC2, you will learn about EC2 and its working.

Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...