7

Chúng tôi biết rằng ElastiCache is not recommended to be accessed outside Amazon instances, vì vậy, chúng tôi đang cố gắng bên dưới nội dung bên trong các trường hợp EC2 của Amazon.Cách kết nối với cụm ElastiCache bằng cách sử dụng node.js

Chúng tôi có ElastiCache Redis Cluster với 9 nút. Khi chúng tôi cố gắng kết nối với nó bằng cách sử dụng normal redis implementation, nó ném some Moved errors

Đã thử retry strategy method theo @Miller. Cũng đã thử RedisCluster với các triển khai unstablestable (poor man).

Không có triển khai nào trong số này đang hoạt động. Bất kỳ đề nghị xin vui lòng?

Trả lời

9

Sharing the code cho độc giả trong tương lai:

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); 
}); 
Các vấn đề liên quan