7

हम उस ElastiCache is not recommended to be accessed outside Amazon instances पता ElastiCache क्लस्टर से कनेक्ट करने, इसलिए हम अमेज़न EC2 उदाहरणों केवल अंदर सामान नीचे कोशिश कर रहे हैं।कैसे Node.js का उपयोग कर

हमारे पास 9 नोड्स के साथ ElastiCache Redis Cluster है। जब हम इसे normal redis implementation का उपयोग कर कनेक्ट करने का प्रयास है, यह some Moved errors

Have की कोशिश की retry strategy method प्रति @Miller के रूप में फेंकता है। और stable (poor man) कार्यान्वयन के साथ RedisCluster भी कोशिश की है।

इनमें से कोई भी कार्यान्वयन कार्य नहीं कर रहा है। कोई सुझाव कृपया?

उत्तर

9

भविष्य पाठकों के लिए Sharing the code:

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); 
}); 
संबंधित मुद्दे