Redis 部署主从哨兵 C#使用,实现自动获取redis缓…

2018-06-17 20:04:02来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

资料查找
https://www.cnblogs.com/tdws/p/5836122.html

https://www.cnblogs.com/lori/p/5794454.html

private static readonly ConnectionMultiplexer _sentinel;

static ISubscriber sub;

static ISubscriber sentinelsub;

ConfigurationOptions sentineloption = new ConfigurationOptions();


ConfigurationOptions option = new ConfigurationOptions();
option.EndPoints.Add("10.55.8.110", 6379);
option.EndPoints.Add("10.55.8.111", 6379);
option.Password = "abc12345!";

option.AllowAdmin = true; //这一句尤其重要,因为主从切换的时间差内,客户端执行keydelete 会发生远程连接错误,经过查证,最后加了这一句不会出错
ConnectionMultiplexer _redis = ConnectionMultiplexer.Connect(option);
IDatabase _db = _redis.GetDatabase();

sentineloption.TieBreaker = "";
sentineloption.EndPoints.Add("10.55.8.110", 26379);
sentineloption.EndPoints.Add("10.55.8.111", 26379);
sentineloption.AllowAdmin = true;
sentineloption.CommandMap = CommandMap.Sentinel;

ConnectionMultiplexer _sentinel = ConnectionMultiplexer.Connect(sentineloption);
option.CommandMap = CommandMap.Sentinel;

sentinelsub = _sentinel.GetSubscriber();
SubSentinel()

public void SubSentinel()
{
sentinelsub.Subscribe("+switch-master", (channel, message) =>
{
lblShow.Text = (string)message;
//Console.WriteLine((string)message);
});
}

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:Sybase SQL anywhere5.5

下一篇:redis 笔记(二)