本文整理汇总了C#中ServiceStack.Redis.RedisClient.DebugSleep方法的典型用法代码示例。如果您正苦于以下问题:C# RedisClient.DebugSleep方法的具体用法?C# RedisClient.DebugSleep怎么用?C# RedisClient.DebugSleep使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ServiceStack.Redis.RedisClient
的用法示例。
在下文中一共展示了RedisClient.DebugSleep方法的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();
}