js连接到ElastiCache集群

js连接到ElastiCache集群

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

问题描述

我们有一个。当我们尝试使用连接到它时,它会抛出

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

尝试了,按照。还尝试了与和实现。

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集群的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 01:38