【问题标题】:Connect to 4 different redis server createClient (without using cluster) on nodejs在nodejs上连接到4个不同的redis服务器createClient(不使用集群)
【发布时间】:2020-01-25 09:08:02
【问题描述】:

我正在尝试找到一种使用 Redis 复制的方法。我需要在不使用集群的情况下连接 4 个不同的 Redis 服务器 - 仅复制(在 node.js 上)。函数createClient只连接一台Redis服务器,我有4台服务器。 有什么方法可以连接到所有 4 个?

【问题讨论】:

  • 您是否在寻找主从设置然后连接?还是分片设置?
  • @ValerianPereira 我正在使用 Elasticache Redis。我想在 nodejs 中使用分片设置。我怎样才能实现它?

标签: javascript node.js redis replication


【解决方案1】:

您可以使用ioredis 包和主从设置来做到这一点。这是一个例子

    const Redis = require("ioredis");

    const slaves = [
      { ip: "127.0.0.1", port: "31231", prio: 1 },
      { ip: "127.0.0.1", port: "31232", prio: 2 }
    ];

    const redis = new Redis({
      sentinels: [
        { host: "127.0.0.1", port: 26379 },
        { host: "127.0.0.1", port: 26380 }
      ],
      name: "mymaster",
      role: "slave",
      preferredSlaves: slaves
    });

【讨论】:

  • 谢谢!奴隶和哨兵有什么区别?我应该在哪里写redis服务器的主机?
  • 哨兵用于监控、通知和自动故障转移。从站基本上是主服务器的副本。如果主人停止工作,哨兵可以将奴隶提升为主人。您可以在文档中阅读所有这些内容,这很有趣
猜你喜欢
  • 1970-01-01
  • 2016-09-09
  • 2015-05-31
  • 2019-07-01
  • 2017-03-06
  • 2021-01-13
  • 2021-10-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多