本文整理汇总了C#中BookSleeve.RedisConnection.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# RedisConnection.Dispose方法的具体用法?C# RedisConnection.Dispose怎么用?C# RedisConnection.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BookSleeve.RedisConnection
的用法示例。
在下文中一共展示了RedisConnection.Dispose方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SelectAndCreateConnection
//.........这里部分代码省略.........
adminPreferred.Wait(adminPreferred.Server.MakeMaster());
}
}
}
else
{
log.WriteLine("Slave should be promoted to master (but not done yet)...");
}
}
break;
case 1:
log.WriteLine("One master found; selecting");
preferred = masters[0];
break;
default:
log.WriteLine("Considering {0} masters...", masters.Count);
preferred = SelectWithTieBreak(log, masters, breakerScores);
break;
}
}
else
{ // we have been instructed to change master server
preferred = masters.Concat(slaves).FirstOrDefault(conn => (conn.Host + ":" + conn.Port) == newMaster);
if (preferred == null)
{
log.WriteLine("Selected new master not available: {0}", newMaster);
}
else
{
int errorCount = 0;
try
{
log.WriteLine("Promoting to master: {0}:{1}...", preferred.Host, preferred.Port);
preferred.Wait(preferred.Server.MakeMaster());
preferred.Strings.Set(0, TieBreakerKey, newMaster);
preferred.Wait(preferred.Publish(RedisMasterChangedChannel, newMaster));
}
catch (Exception ex)
{
log.WriteLine("\t{0}", ex.Message);
errorCount++;
}
if (errorCount == 0) // only make slaves if the master was happy
{
foreach (var conn in masters.Concat(slaves))
{
if (conn == preferred) continue; // can't make self a slave!
try
{
log.WriteLine("Enslaving: {0}:{1}...", conn.Host, conn.Port);
// set the tie-breaker **first** in case of problems
conn.Strings.Set(0, TieBreakerKey, newMaster);
// and broadcast to anyone who thinks this is the master
conn.Publish(RedisMasterChangedChannel, newMaster);
// now make it a slave
conn.Wait(conn.Server.MakeSlave(preferred.Host, preferred.Port));
}
catch (Exception ex)
{
log.WriteLine("\t{0}",ex.Message);
errorCount++;
}
}
}
if (errorCount != 0)
{
log.WriteLine("Things didn't go smoothly; CHECK WHAT HAPPENED!");
}
// want the connection disposed etc
preferred = null;
}
}
if (preferred == null)
{
selectedConfiguration = null;
}
else
{
selectedConfiguration = preferred.Host + ":" + preferred.Port;
log.WriteLine("Selected server {0}", selectedConfiguration);
}
availableEndpoints = (from conn in masters.Concat(slaves)
select conn.Host + ":" + conn.Port).ToArray();
return preferred;
}
finally
{
foreach (var conn in connections)
{
if (conn != null && conn != preferred) try { conn.Dispose(); }
catch { }
}
}
}
示例2: SelectAndCreateConnection
//.........这里部分代码省略.........
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);
}
}
Tuple<string, int> finalChoice;
switch (discoveredPairs.Count)
{
case 0:
log.WriteLine("No sentinels nominated a master; unable to connect");
finalChoice = null;
break;
case 1:
finalChoice = discoveredPairs.Single().Key;
log.WriteLine("Sentinels nominated unanimous master: {0}:{1}", finalChoice.Item1,
finalChoice.Item2);
break;
default:
finalChoice = discoveredPairs.OrderByDescending(kvp => kvp.Value).First().Key;
log.WriteLine("Sentinels nominated multiple masters; choosing arbitrarily: {0}:{1}",
finalChoice.Item1, finalChoice.Item2);
break;
}
if (finalChoice != null)
{
RedisConnection toBeDisposed = null;
try
{
// good bet that in this scenario the input didn't specify any actual redis servers, so we'll assume open a new one
log.WriteLine("Opening nominated master: {0}:{1}...", finalChoice.Item1, finalChoice.Item2);
toBeDisposed = new RedisConnection(finalChoice.Item1, finalChoice.Item2,
allowAdmin: allowAdmin, syncTimeout: syncTimeout);
toBeDisposed.Wait(toBeDisposed.Open());
if (toBeDisposed.ServerType == ServerType.Master)
{
RedisConnection tmp = toBeDisposed;
toBeDisposed = null; // so we don't dispose it
selectedConfiguration = tmp.Host + ":" + tmp.Port;
availableEndpoints = new[] {selectedConfiguration};
return tmp;
}
else
{
log.WriteLine("Server is {0} instead of a master", toBeDisposed.ServerType);
}
}
catch (Exception ex)
{
log.WriteLine("Error: {0}", ex.Message);
}
finally
{
// dispose if something went sour
using (toBeDisposed)
{
}
}
}