gpt4 book ai didi

node.js - Node : How to connect to multiple redis?

转载 作者:可可西里 更新时间:2023-11-01 10:55:34 28 4
gpt4 key购买 nike

如何用nodejs架设两台redis服务器(master/slave)?
我用 node_redis , 已经尝试过 redis://host:port,host2:port2?db=10&password=bar

var connectionString = 'redis://host:port,host2:port2?db=10&password=bar'
var client = redis.createClient(connectionString);
client.set('key','value',function(err,reply){
console.log(err); //the db option is added twice and does not match
console.log(reply);
});

最佳答案

几个月后我发现ioredis可以帮助使用 nodejs 集群作业!

var Redis = require('ioredis');

var cluster = new Redis.Cluster([{
port: 6380,
host: '127.0.0.1'
}, {
port: 6381,
host: '127.0.0.1'
}]);

cluster.set('foo', 'bar');
cluster.get('foo', function (err, res) {
// res === 'bar'
});

关于node.js - Node : How to connect to multiple redis?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43095588/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com