鸿 网 互 联 www.68idc.cn

当前位置 : 服务器租用 > 数据库 > 其他数据库 > >

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

来源:互联网 作者:佚名 时间:2018-01-26 18:36
资料查找 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 sentinel

资料查找
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);
});
}

网友评论
<