0
Redis接続をしようとしていますが、「マスタ」ポートと2つのスレーブがあります。私はセンチネルでこれをやりたい。マスタとスレーブでRedis接続を作成する方法
私の実際にredisに接続するコードは、実際は非難されています。
ここに私のコードです。
var redis = require('redis');
var client = redis.createClient(config.redis_port, config.redis_host,
{no_ready_check: true});
if (config.redis_password != null) {
client.auth(config.redis_password, function (err) {
if (err) throw err;
});
}
client.on('connect', function(err, res) {
logger.info('Connected to Redis ' + process.pid);
redisIsReady = true;
});
client.on('error', function(err) {
logger.error('Error connecting to Redis ' + process.pid);
redisIsReady = false;
});
client.get(objectRequest.customerId, function(err, reply) {
if (reply != null && reply >= config.max_requests) {
var json = JSON.stringify({errorCode: validationErrors.TOO_MANY_REQUEST,
description: errorMessage[validationErrors.TOO_MANY_REQUEST]});
res.setHeader('Retry-After', config.retry_after);
res.setHeader('Content-Type', 'application/json');
res.setHeader('Content-Length', json.length);
res.writeHead(429);
res.write(json);
return res.end();
}
// Set a value with an expiration
client.incr(objectRequest.customerId);
client.expire(objectRequest.customerId, config.retry_after);
});
私は他の記事を読んでいます。私はおそらくioredisでそれを行うだろうと思います。しかし、私はRedisについて多くのことを知っていません...
私はredisへの接続を行いたいと思います。マスターがダウンしていると、自動的にスレーブに接続します。
私は
ロス、あなたは私を助け願っています。
時には 'objectRequest.customerId'の値を取得しようとすると、クライアントがサーバに接続されておらず、認証されている可能性があります。 – Vishnu
それは私の問題ではない、私はredisへの接続をしたいとマスターがダウンしている場合、これは自動的にスレーブに接続します。あなたの答えに感謝します。 – Roth
https://stackoverflow.com/questions/34155977/redis-promoting-a-slave-to-master-manual – Vishnu