当前位置: 首页>>代码示例>>C#>>正文


C# RedisConnection.WaitAll方法代码示例

本文整理汇总了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");
                }
            }
        }
开发者ID:raycode,项目名称:booksleeve,代码行数:47,代码来源:Connection.cs

示例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);
        }
开发者ID:raycode,项目名称:booksleeve,代码行数:30,代码来源:PubSub.cs


注:本文中的BookSleeve.RedisConnection.WaitAll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。