本文整理汇总了C#中ServiceStack.Redis.RedisClient.GetServerRole方法的典型用法代码示例。如果您正苦于以下问题:C# RedisClient.GetServerRole方法的具体用法?C# RedisClient.GetServerRole怎么用?C# RedisClient.GetServerRole使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ServiceStack.Redis.RedisClient
的用法示例。
在下文中一共展示了RedisClient.GetServerRole方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateRedisClient
public virtual RedisClient CreateRedisClient(RedisEndpoint config, bool readWrite)
{
var client = RedisConfig.ClientFactory(config);
if (readWrite && RedisConfig.VerifyMasterConnections)
{
var role = client.GetServerRole();
if (role != RedisServerRole.Master)
{
log.Error("Redis Master Host '{0}' is {1}. Resetting allHosts...".Fmt(config.GetHostString(), role));
var newMasters = new List<RedisEndpoint>();
var newSlaves = new List<RedisEndpoint>();
RedisClient masterClient = null;
foreach (var hostConfig in allHosts)
{
try
{
var testClient = new RedisClient(hostConfig) {
ConnectTimeout = RedisConfig.HostLookupTimeout
};
var testRole = testClient.GetServerRole();
switch (testRole)
{
case RedisServerRole.Master:
newMasters.Add(hostConfig);
if (masterClient == null)
masterClient = testClient;
break;
case RedisServerRole.Slave:
newSlaves.Add(hostConfig);
break;
}
}
catch { /* skip */ }
}
if (masterClient == null)
{
var errorMsg = "No master found in: " + string.Join(", ", allHosts.Map(x => x.GetHostString()));
log.Error(errorMsg);
throw new Exception(errorMsg);
}
ResetMasters(newMasters);
ResetSlaves(newSlaves);
return masterClient;
}
}
return client;
}
示例2: CreateRedisClient
public virtual RedisClient CreateRedisClient(RedisEndpoint config, bool readWrite)
{
var client = RedisConfig.ClientFactory(config);
if (readWrite)
{
var role = client.GetServerRole();
if (role != RedisServerRole.Master)
{
try
{
var stopwatch = Stopwatch.StartNew();
while (true)
{
var masterConfig = sentinel.GetMaster();
var master = RedisConfig.ClientFactory(masterConfig);
var masterRole = master.GetServerRole();
if (masterRole == RedisServerRole.Master)
return master;
if (stopwatch.Elapsed > sentinel.MaxWaitBetweenSentinelLookups)
throw new TimeoutException("Max Wait Between Sentinel Lookups Elapsed: {0}"
.Fmt(sentinel.MaxWaitBetweenSentinelLookups.ToString()));
Thread.Sleep(sentinel.WaitBetweenSentinelLookups);
}
}
catch (Exception ex)
{
log.Error("Redis Master Host '{0}' is {1}. Resetting allHosts...".Fmt(config.GetHostString(), role), ex);
var newMasters = new List<RedisEndpoint>();
var newSlaves = new List<RedisEndpoint>();
RedisClient masterClient = null;
foreach (var hostConfig in allHosts)
{
try
{
var testClient = new RedisClient(hostConfig)
{
ConnectTimeout = RedisConfig.HostLookupTimeout
};
var testRole = testClient.GetServerRole();
switch (testRole)
{
case RedisServerRole.Master:
newMasters.Add(hostConfig);
if (masterClient == null)
masterClient = testClient;
break;
case RedisServerRole.Slave:
newSlaves.Add(hostConfig);
break;
}
}
catch { /* skip */ }
}
if (masterClient == null)
{
var errorMsg = "No master found in: " + string.Join(", ", allHosts.Map(x => x.GetHostString()));
log.Error(errorMsg);
throw new Exception(errorMsg);
}
ResetMasters(newMasters);
ResetSlaves(newSlaves);
return masterClient;
}
}
}
return client;
}