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


C# RedisClient.Pipeline方法代码示例

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

示例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");
              }
        }
开发者ID:johanhelsing,项目名称:sider,代码行数:82,代码来源:SortSample.cs


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