【问题标题】:Node.js Connecting to redis clusterNode.js 连接redis集群
【发布时间】:2020-08-23 19:32:36
【问题描述】:

有大量示例和资源可用于连接到 redis “服务器”,但不能连接到 redis “集群”。

我目前拥有的是:

const redis = require("redis"); 
const client = redis.createClient({
 port      : 6379,               // replace with your port
 host      : '10.0.0.100',        // replace with your hostanme or IP address
 password  : 'Notforyou',    // replace with your password
 // optional, if using SSL
 // use `fs.readFile[Sync]` or another method to bring these values in
 tls       : {
   key  : stringValueOfKeyFile,  
   cert : stringValueOfCertFile,
   ca   : [ stringValueOfCaCertFile ]
 }
});

但这是针对单个 redis 服务器而不是集群。我将如何连接到我的集群?

【问题讨论】:

    标签: node.js redis redis-cluster


    【解决方案1】:

    看看这个库ioredis

    我认为这将帮助您解决问题。

    【讨论】:

    【解决方案2】:

    redis npm package 中的自述文件选项卡有此链接 (Clustering Guide),解释了如何使用标题“集群”下的节点连接到 redis 集群。这很简单,创建一个集群而不是创建客户端,并按照example 中给出的配置节点 url

    【讨论】:

      猜你喜欢
      • 2019-08-03
      • 2015-10-13
      • 2015-11-12
      • 1970-01-01
      • 1970-01-01
      • 2019-02-02
      • 1970-01-01
      • 2017-12-27
      • 1970-01-01
      相关资源
      最近更新 更多