如何使用node.js连接到ElastiCache集群 [英] How to connect to ElastiCache cluster using node.js

查看:140
本文介绍了如何使用node.js连接到ElastiCache集群的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我们知道不建议在Amazon实例外部访问ElastiCache ,因此我们仅在Amazon EC2实例内部尝试以下方法。

We know that ElastiCache is not recommended to be accessed outside Amazon instances, so we're trying below stuff inside Amazon EC2 instances only.

我们有一个具有9个节点的ElastiCache Redis群集。当我们尝试使用常规redis实现连接到它时,它会抛出一些已移动的错误

We've got a ElastiCache Redis Cluster with 9 nodes. When we try to connect to it using normal redis implementation, it throws some Moved errors

尝试了重试策略方法,按照 @米勒。还尝试了 RedisCluster 不稳定稳定(可怜的人)实现。

Have tried the retry strategy method as per @Miller. Have also tried RedisCluster with unstable and stable (poor man) implementations.

这些实现均无用。有什么建议吗?

None of these implementations are working. Any suggestions please?

推荐答案


共享代码供将来的读者使用:



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

这篇关于如何使用node.js连接到ElastiCache集群的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆