sql >> Databáze >  >> NoSQL >> Redis

Jak vytvořit spojení Redis s Master a Slave

Konečně jsem to udělal a funguje to dobře.

Nechám vám zde svůj kód, doufám, že to pomůže ostatním!

var Redis = require('ioredis');
// preferredSlaves array format
var preferredSlaves = [
  { ip: config.redis_slave_1, port: config.redis_port, prio: 1 },
  { ip: config.redis_slave_2, port: config.redis_port, prio: 2 }
];
var redis = new Redis({
  port: config.redis_port,
  host: config.redis_host,
  sentinels: [{ host: config.redis_sentinel_1, port: config.redis_sentinel }, { host: config.redis_sentinel_2, port: config.redis_sentinel }, { host: config.redis_sentinel_3, port: config.redis_sentinel }],
  name: config.redis_master_name,
  password: config.redis_password,
  preferredSlaves: preferredSlaves
});

redis.on('connect', function(err, res) {
  logger.info('Connected to Redis ' + process.pid);
  redisIsReady = true;
  console.log('Connected to Redis ' + process.pid + " REDIS " + JSON.stringify(redis.options) )
});

redis.on('error', function(err) {
  logger.error('Error connecting to Redis ' + process.pid);
  redisIsReady = false;
  console.log('error to Redis ' + err)
});

Děkuji za všechny vaše odpovědi,

S pozdravem!!




  1. Proč byste měli stále používat úložiště MMAPv1 pro MongoDB

  2. Mongo:jak třídit podle externí hmotnosti

  3. Jak opravit VAROVÁNÍ při spuštění obrazu redis:alpine Docker

  4. Souběžnost v gopkg.in/mgo.v2 (Mongo, Go)