本文整理汇总了C#中RedisClient.Pipeline方法的典型用法代码示例。如果您正苦于以下问题:C# RedisClient.Pipeline方法的具体用法?C# RedisClient.Pipeline怎么用?C# RedisClient.Pipeline使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RedisClient
的用法示例。
在下文中一共展示了RedisClient.Pipeline方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
public override void Run()
{
var client = new RedisClient<int>(RedisSettings.Default);
// NOTE: This is for demonstartion purpose only
// real-world code should just use MGet and MSet which are made
// specifically for tasks like this
// initialize 1000 counters with a number
var success = client
.Pipeline(c =>
{
var rand = new Random();
for (var i = 0; i < CounterAmount; i++)
c.Set("counter" + i.ToString(), rand.Next(100, 999));
})
.Cast<bool>()
.All(b => b);
WriteLine(success ?
"All counters set to [100,999]." :
"Unable to set some counters");
var verified = client
.Pipeline(c => Enumerable
.Range(0, 1000)
.Select(n => c.Get("counter" + n.ToString()))
.AsEnumerable())
.Cast<int>()
.All(n => n >= 100 && n < 1000);
WriteLine(verified ?
"Counter values verified." :
"Some counters are invalid.");
}
示例2: Run
public override void Run()
{
var personnels = Personnel.GetSamplePersonnels();
var client = new RedisClient();
var listKey = "personnels";
// setup sample data
client.Pipeline(c =>
{
client.Del(listKey);
foreach (var person in personnels) {
var idStr = person.Id.ToString();
c.LPush(listKey, idStr);
c.HSet(idStr, "name", person.Name);
c.HSet(idStr, "email", person.Email);
c.HIncrBy(idStr, "age", person.Age);
c.HIncrBy(idStr, "salary", person.Salary);
c.HSet(idStr, "json", person.ToJson());
}
});
while (true) {
WriteLine("0. List personnels sorted by yearly income.");
WriteLine("1. List personnels sorted by age.");
WriteLine("2. List personnels sorted by id descending.");
WriteLine("3. List personnels sorted by name.");
WriteLine("4. List all personnel emails.");
string[] result;
var parseResult = true;
switch (ReadLine()) {
case "0": {
result = client.Sort(listKey,
byPattern: "*->salary",
getPattern: new[] { "*->json" });
} break;
case "1": {
parseResult = true;
result = client.Sort(listKey,
byPattern: "*->age",
getPattern: new[] { "*->json" });
} break;
case "2": {
parseResult = true;
result = client.Sort(listKey,
descending: true,
getPattern: new[] { "*->json" });
} break;
case "3": {
result = client.Sort(listKey,
byPattern: "*->name",
alpha: true,
getPattern: new[] { "*->json" });
} break;
case "4": {
result = client.Sort(listKey,
byPattern: "nosort", // non-existent key
getPattern: new[] { "*->email" });
parseResult = false;
} break;
default: continue;
}
if (parseResult)
result = result
.Select(json => Personnel.FromJson(json).ToString())
.ToArray();
WriteLine("\r\nResults:");
Array.ForEach(result, WriteLine);
WriteLine("\r\n");
}
}