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


C# RedisClient.Scan方法代码示例

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


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

示例1: TestScan

        public void TestScan()
        {
            var reply1 = "*2\r\n$1\r\n0\r\n*3\r\n$5\r\ntest1\r\n$5\r\ntest2\r\n$5\r\ntest3\r\n";
            var reply2 = "*2\r\n$1\r\n0\r\n*0\r\n";
            var reply3 = "*2\r\n$1\r\n0\r\n*0\r\n";
            var reply4 = "*2\r\n$1\r\n0\r\n*0\r\n";
            using (var mock = new FakeRedisSocket(reply1, reply2, reply3, reply4))
            using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
            {
                var resp = redis.Scan(0);
                Assert.AreEqual(0, resp.Cursor);
                Assert.AreEqual(3, resp.Items.Length);
                for (int i = 0; i < resp.Items.Length; i++)
                    Assert.AreEqual("test" + (i + 1), resp.Items[i]);
                Assert.AreEqual("*2\r\n$4\r\nSCAN\r\n$1\r\n0\r\n", mock.GetMessage());

                redis.Scan(1, pattern: "pattern");
                Assert.AreEqual("*4\r\n$4\r\nSCAN\r\n$1\r\n1\r\n$5\r\nMATCH\r\n$7\r\npattern\r\n", mock.GetMessage());

                redis.Scan(2, count: 5);
                Assert.AreEqual("*4\r\n$4\r\nSCAN\r\n$1\r\n2\r\n$5\r\nCOUNT\r\n$1\r\n5\r\n", mock.GetMessage());

                redis.Scan(3, pattern: "pattern", count: 5);
                Assert.AreEqual("*6\r\n$4\r\nSCAN\r\n$1\r\n3\r\n$5\r\nMATCH\r\n$7\r\npattern\r\n$5\r\nCOUNT\r\n$1\r\n5\r\n", mock.GetMessage());
            }
        }
开发者ID:DTBruce,项目名称:csredis,代码行数:26,代码来源:KeyTests.cs

示例2: TestScan

        public void TestScan()
        {
            var reply1 = "*2\r\n$1\r\n0\r\n*3\r\n$5\r\ntest1\r\n$5\r\ntest2\r\n$5\r\ntest3\r\n";
            var reply2 = "*2\r\n$1\r\n0\r\n*0\r\n";
            var reply3 = "*2\r\n$1\r\n0\r\n*0\r\n";
            var reply4 = "*2\r\n$1\r\n0\r\n*0\r\n";
            using(var mock = new MockConnector("localhost", 9999, reply1, reply2, reply3, reply4))
            using(var redis = new RedisClient(mock))
            {
                var resp = (redis.Scan(0) as RedisScan<string>).GetEnumerator() as RedisScan<string>.Enumerator;
                for(int i = 0; i < 3; i++)
                {
                    resp.MoveNext();
                    Assert.Equal(3 - i - 1, resp.Items.Length);
                    Assert.Equal(0, resp.Cursor);
                    Assert.Equal("test" + (i + 1), resp.Current);
                }
                Assert.Equal("*2\r\n$4\r\nSCAN\r\n$1\r\n0\r\n", mock.GetMessage());

                redis.Scan(1, pattern: "pattern").ToArray();
                Assert.Equal("*4\r\n$4\r\nSCAN\r\n$1\r\n1\r\n$5\r\nMATCH\r\n$7\r\npattern\r\n", mock.GetMessage());

                redis.Scan(2, count: 5).ToArray();
                Assert.Equal("*4\r\n$4\r\nSCAN\r\n$1\r\n2\r\n$5\r\nCOUNT\r\n$1\r\n5\r\n", mock.GetMessage());

                redis.Scan(3, pattern: "pattern", count: 5).ToArray();
                Assert.Equal("*6\r\n$4\r\nSCAN\r\n$1\r\n3\r\n$5\r\nMATCH\r\n$7\r\npattern\r\n$5\r\nCOUNT\r\n$1\r\n5\r\n", mock.GetMessage());
            }


            this.RealCall(redis =>
            {
                var dict = new RedisDictionary();
                for(int i = 1; i < 21; i++)
                {
                    dict.Add("key" + i, "value" + i);
                }
                redis.MSet(dict);
                Assert.Equal(20, redis.Scan().Count());
            });
        }
开发者ID:glorylee,项目名称:Aoite,代码行数:41,代码来源:RedisKeyTests.cs


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