How to connect to an ElastiCache cluster using node.js

We know that ElastiCache is not recommended to be opened outside of Amazon instances , so we only try to do this inside Amazon EC2 instances.

We have an ElastiCache Redis Cluster with 9 nodes. When we try to connect to it using the usual redis implementation , it throws some Moved errors

We tried the repeat strategy method according to @Miller . You also tried RedisCluster with unstable and stable (poor person) .

None of these implementations work. Any suggestions please?

+7
amazon-web-services amazon-ec2 amazon-elasticache redis
source share
1 answer

Code exchange for future readers:

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); }); 
+9
source share

All Articles