本文整理匯總了C#中ServiceStack.Redis.RedisClient.GetHostString方法的典型用法代碼示例。如果您正苦於以下問題:C# RedisClient.GetHostString方法的具體用法?C# RedisClient.GetHostString怎麽用?C# RedisClient.GetHostString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ServiceStack.Redis.RedisClient
的用法示例。
在下文中一共展示了RedisClient.GetHostString方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Execute
public void Execute()
{
RedisConfig.DisableVerboseLogging = true;
LogManager.LogFactory = new ConsoleLogFactory(debugEnabled: true);
log = LogManager.GetLogger(GetType());
RedisConfig.DefaultReceiveTimeout = 10000;
OnSetUp();
using (var sentinel = CreateSentinel())
{
if (UseRedisManagerPool)
{
sentinel.RedisManagerFactory = (masters, slaves) =>
new RedisManagerPool(masters);
}
var redisManager = sentinel.Start();
int i = 0;
var clientTimer = new Timer
{
Interval = MessageInterval,
Enabled = true
};
clientTimer.Elapsed += (sender, args) =>
{
log.Debug("clientTimer.Elapsed: " + (i++));
try
{
string key = null;
using (var master = (RedisClient)redisManager.GetClient())
{
var counter = master.Increment("key", 1);
key = "key" + counter;
log.DebugFormat("Set key {0} in read/write client #{1}@{2}", key, master.Id, master.GetHostString());
master.SetValue(key, "value" + 1);
}
using (var readOnly = (RedisClient)redisManager.GetReadOnlyClient())
{
log.DebugFormat("Get key {0} in read-only client #{1}@{2}", key, readOnly.Id, readOnly.GetHostString());
var value = readOnly.GetValue(key);
log.DebugFormat("{0} = {1}", key, value);
}
}
catch (ObjectDisposedException ex)
{
log.DebugFormat("ObjectDisposedException detected, disposing timer...");
clientTimer.Dispose();
}
catch (Exception ex)
{
log.Error("Error in Timer", ex);
}
if (i % 10 == 0)
log.Debug(RedisStats.ToDictionary().Dump());
};
log.Debug("Sleeping for 5000ms...");
Thread.Sleep(5000);
log.Debug("Failing over master...");
var masterHost = sentinel.ForceMasterFailover();
log.Debug("{0} was failed over".Fmt(masterHost));
log.Debug("Sleeping for 20000ms...");
Thread.Sleep(20000);
try
{
var debugConfig = sentinel.GetMaster();
using (var master = new RedisClient(debugConfig))
{
log.Debug("Putting master '{0}' to sleep for 35 seconds...".Fmt(master.GetHostString()));
master.DebugSleep(35);
}
}
catch (Exception ex)
{
log.Error("Error retrieving master for DebugSleep()", ex);
}
log.Debug("After DEBUG SLEEP... Sleeping for 5000ms...");
Thread.Sleep(5000);
log.Debug("RedisStats:");
log.Debug(RedisStats.ToDictionary().Dump());
System.Console.ReadLine();
}
OnTearDown();
}