我正在尝试做一个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,如果主服务器宕机了,它会自动连接到从服务器。
我希望你能帮我
罗斯。
https://stackoverflow.com/questions/44431036
复制相似问题