本文整理汇总了C#中BookSleeve.RedisConnection.QuerySentinelMaster方法的典型用法代码示例。如果您正苦于以下问题:C# RedisConnection.QuerySentinelMaster方法的具体用法?C# RedisConnection.QuerySentinelMaster怎么用?C# RedisConnection.QuerySentinelMaster使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BookSleeve.RedisConnection
的用法示例。
在下文中一共展示了RedisConnection.QuerySentinelMaster方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SelectAndCreateConnection
//.........这里部分代码省略.........
{
if (tiebreak.Wait(syncTimeout))
{
string key = tiebreak.Result;
if (string.IsNullOrWhiteSpace(key)) continue;
int score;
if (breakerScores.TryGetValue(key, out score)) breakerScores[key] = score + 1;
else breakerScores.Add(key, 1);
}
}
catch
{
/* if a node is down, that's fine too */
}
}
// see if any of our nodes are sentinels that know about the named service
List<Tuple<RedisConnection, Task<Tuple<string, int>>>> sentinelNodes = null;
foreach (RedisConnection conn in connections)
{
// the "wait" we did during tie-breaker detection means we should now know what each server is
if (conn.ServerType == ServerType.Sentinel)
{
if (string.IsNullOrEmpty(serviceName))
{
log.WriteLine("Sentinel discovered, but no serviceName was specified; ignoring {0}:{1}",
conn.Host, conn.Port);
}
else
{
log.WriteLine("Querying sentinel {0}:{1} for {2}...", conn.Host, conn.Port, serviceName);
if (sentinelNodes == null)
sentinelNodes = new List<Tuple<RedisConnection, Task<Tuple<string, int>>>>();
sentinelNodes.Add(Tuple.Create(conn, conn.QuerySentinelMaster(serviceName)));
}
}
}
// wait for sentinel results, if any
if (sentinelNodes != null)
{
var discoveredPairs = new Dictionary<Tuple<string, int>, int>();
foreach (var pair in sentinelNodes)
{
RedisConnection conn = pair.Item1;
try
{
Tuple<string, int> master = conn.Wait(pair.Item2);
if (master == null)
{
log.WriteLine("Sentinel {0}:{1} is not configured for {2}", conn.Host, conn.Port,
serviceName);
}
else
{
log.WriteLine("Sentinel {0}:{1} nominates {2}:{3}", conn.Host, conn.Port, master.Item1,
master.Item2);
int count;
if (discoveredPairs.TryGetValue(master, out count)) count = 0;
discoveredPairs[master] = count + 1;
}
}
catch (Exception ex)
{
log.WriteLine("Error from sentinel {0}:{1} - {2}", conn.Host, conn.Port, ex.Message);
}