本文整理汇总了C#中BookSleeve.RedisConnection.WaitAll方法的典型用法代码示例。如果您正苦于以下问题:C# RedisConnection.WaitAll方法的具体用法?C# RedisConnection.WaitAll怎么用?C# RedisConnection.WaitAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BookSleeve.RedisConnection
的用法示例。
在下文中一共展示了RedisConnection.WaitAll方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestSubscriberNameOnRemote
private void TestSubscriberNameOnRemote(bool setName)
{
string id = Config.CreateUniqueName();
using (var pub = new RedisConnection(Config.RemoteHost, allowAdmin: true))
using (var sub = new RedisSubscriberConnection(Config.RemoteHost))
{
List<string> errors = new List<string>();
EventHandler<BookSleeve.ErrorEventArgs> errorHandler = (sender, args) =>
{
lock (errors) errors.Add(args.Exception.Message);
};
pub.Error += errorHandler;
sub.Error += errorHandler;
if (setName)
{
pub.Name = "pub_" + id;
sub.Name = "sub_" + id;
}
int count = 0;
var subscribe = sub.Subscribe("foo"+id, (key,payload) => Interlocked.Increment(ref count));
Task pOpen = pub.Open(), sOpen = sub.Open();
pub.WaitAll(pOpen, sOpen, subscribe);
Assert.AreEqual(0, Interlocked.CompareExchange(ref count, 0, 0), "init message count");
pub.Wait(pub.Publish("foo" + id, "hello"));
PubSub.AllowReasonableTimeToPublishAndProcess();
var clients = setName ? pub.Wait(pub.Server.ListClients()) : null;
Assert.AreEqual(1, Interlocked.CompareExchange(ref count, 0, 0), "got message");
lock (errors)
{
foreach (var error in errors)
{
Console.WriteLine(error);
}
Assert.AreEqual(0, errors.Count, "zero errors");
}
if (setName)
{
Assert.AreEqual(1, clients.Count(x => x.Name == pub.Name), "pub has name");
Assert.AreEqual(1, clients.Count(x => x.Name == sub.Name), "sub has name");
}
}
}
示例2: TestMassivePublishWithWithoutFlush
private void TestMassivePublishWithWithoutFlush(RedisConnection conn, string caption)
{
const int loop = 100000;
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
GC.WaitForPendingFinalizers();
var tasks = new Task[loop];
var withFlush = Stopwatch.StartNew();
for (int i = 0; i < loop; i++)
tasks[i] = conn.Publish("foo", "bar");
conn.WaitAll(tasks);
withFlush.Stop();
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
GC.WaitForPendingFinalizers();
conn.SuspendFlush();
var withoutFlush = Stopwatch.StartNew();
for (int i = 0; i < loop; i++)
tasks[i] = conn.Publish("foo", "bar");
conn.ResumeFlush();
conn.WaitAll(tasks);
withoutFlush.Stop();
Assert.Less(1, 2, "sanity check");
Assert.Less(withoutFlush.ElapsedMilliseconds, withFlush.ElapsedMilliseconds, caption);
Console.WriteLine("{2}: {0}ms (eager-flush) vs {1}ms (suspend-flush)",
withFlush.ElapsedMilliseconds, withoutFlush.ElapsedMilliseconds, caption);
}