【问题标题】:How to connect to ElastiCache cluster using node.js如何使用 node.js 连接到 ElastiCache 集群
【发布时间】:2017-10-07 22:39:13
【问题描述】:

我们知道ElastiCache is not recommended to be accessed outside Amazon instances,因此我们仅在 Amazon EC2 实例中尝试以下内容。

我们有一个有 9 个节点的 ElastiCache Redis Cluster。当我们尝试使用normal redis implementation 连接到它时,它会抛出some Moved errors

已按照@Miller 尝试了retry strategy method。还尝试了 RedisClusterunstablestable (poor man) 实现。

这些实现都不起作用。请问有什么建议吗?

【问题讨论】:

    标签: node.js amazon-web-services amazon-ec2 redis amazon-elasticache


    【解决方案1】:

    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);
    });
    

    【讨论】:

    • 感谢分享,但它对我不起作用。你用的是什么配置的elasticache redis?
    • @Ultrablendz 请再次检查链接!我已经更新了
    • 感谢您更新链接,但是,它不适用于启用集群模式的 AWS Elastiredis。我也在尝试从 lamda 实例而不是 ec2 实例中解决它,尽管这无关紧要。
    • 您能否建议包含身份验证的方法,我在 elasticache 实例上进行传输中的加密,我无法使用 client.auth 进行身份验证,代码只是死在那里,我确定我错过了什么在互联网上找不到任何东西
    • @SalimShamim 请发布一个新问题!
    猜你喜欢
    • 2016-05-03
    • 2016-10-23
    • 2019-09-12
    • 1970-01-01
    • 2015-02-10
    • 2015-11-21
    • 2020-03-31
    • 1970-01-01
    • 2015-09-07
    相关资源
    最近更新 更多