我们知道ElastiCache is not recommended to be accessed outside Amazon instances,所以我们只在Amazon EC2实例中尝试以下内容。
我们有一个包含9个节点的ElastiCache Redis Cluster。当我们尝试使用normal redis implementation连接到它时,它会抛出some Moved errors
已根据retry strategy method尝试了@Miller。还尝试了RedisCluster和unstable实施{。}}。
这些实现都不起作用。有什么建议吗?
答案 0 :(得分:17)
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);
});