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


C# Bucket.Set方法代码示例

本文整理汇总了C#中Bucket.Set方法的典型用法代码示例。如果您正苦于以下问题:C# Bucket.Set方法的具体用法?C# Bucket.Set怎么用?C# Bucket.Set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Bucket的用法示例。


在下文中一共展示了Bucket.Set方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SetAndGetKetchupAsync

        public static double SetAndGetKetchupAsync(int numberOfOperations, Bucket cli)
        {
            var counter = numberOfOperations;
            var start = DateTime.Now;
            var sync = new object();

            //simulate synchronous operation
            TestAsync(180, (success, fail) =>
            {
                for (var i = 0; i < numberOfOperations; i++)
                {
                    var key = "kc" + i;
                    var value = key + " value";
                    var bucket = "default";
                    object asyncState = new DemoAsyncState { Key = key };
                    cli.Set(key, value, s =>
                        {
                            lock (sync)
                            {
                                dynamic state = s;
                                var c = --counter;
                                if (debugAsync) Console.WriteLine(c + ": " + state.Key + ": set");
                                if (c == 0) success(s);
                            }
                        }, fail, asyncState);
                }
            });

            counter = numberOfOperations;
            TestAsync(60, (success, fail) =>
            {
                for (var i = 0; i < numberOfOperations; i++)
                {
                    var key = "kc" + i;
                    var bucket = "default";

                    //get is fired on success return of set
                    var asyncState = new DemoAsyncState { Key = key, Counter = counter };
                    cli.Get<string>(key,
                        (val, s) =>
                        {
                            lock (sync)
                            {
                                dynamic state = s;
                                var c = --counter;
                                if (debugAsync) Console.WriteLine(c + ": " + state.Key + ": " + val);
                                if (c == 0) success(s);
                            }
                        },
                        s1 =>
                        {
                            lock (sync)
                            {
                                dynamic state1 = s1;
                                var c1 = --counter;
                                if (debugAsync) Console.WriteLine(c1 + ": " + state1.Key + ": miss");
                                if (c1 == 0) success(s1);
                            }
                        },
                        fail, asyncState
                    );
                }
            });

            return (DateTime.Now - start).TotalSeconds;
        }
开发者ID:sdether,项目名称:Ketchup,代码行数:66,代码来源:Program.cs

示例2: SetAndGetKetchupSync

        public static double SetAndGetKetchupSync(int numberOfOperations, Bucket cli)
        {
            var start = DateTime.Now;

            for (var i = 0; i < numberOfOperations; i++)
            {
                var key = "kc" + i;
                var value = key + " value";
                cli.Set(key, value);
            }

            for (var i = 0; i < numberOfOperations; i++)
            {
                var key = "kc" + i;
                var expected = key + " value";
                var actual = cli.Get<string>(key);
                if (actual != expected) Console.WriteLine("Values did not match. expected: " + expected + ". actual: " + actual);
            }

            return (DateTime.Now - start).TotalSeconds;
        }
开发者ID:sdether,项目名称:Ketchup,代码行数:21,代码来源:Program.cs


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