本文整理汇总了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;
}
示例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;
}