From cb74222185713f6fa021ba062f5429f1f33d118d Mon Sep 17 00:00:00 2001 From: bicijinlian Date: Thu, 5 Jul 2018 15:31:19 +0800 Subject: [PATCH] SortedSet Test --- RedisStudyTest/RedisSortedSetStudyTest.cs | 89 ++++++++++++++++------- 1 file changed, 61 insertions(+), 28 deletions(-) diff --git a/RedisStudyTest/RedisSortedSetStudyTest.cs b/RedisStudyTest/RedisSortedSetStudyTest.cs index 13328db..b9cd168 100644 --- a/RedisStudyTest/RedisSortedSetStudyTest.cs +++ b/RedisStudyTest/RedisSortedSetStudyTest.cs @@ -242,8 +242,40 @@ namespace RedisStudyTest [Fact] public void SortedSetLengthByValue_Exclude_Test() { + SortedSetEntry[] sortedSetEntries = new SortedSetEntry[] + { + new SortedSetEntry("first",0), + new SortedSetEntry("second",0), + new SortedSetEntry("third",0), + new SortedSetEntry("four",0), + new SortedSetEntry("five",0), + }; + redisSortedSetStudy.SortedSetAdd(defaultRedisKey, sortedSetEntries); + + //默认:Exclude.None [Start,Stop] + var memberCount = redisSortedSetStudy.SortedSetLengthByValue(defaultRedisKey, "first", "four", Exclude.None, CommandFlags.None); + Assert.Equal(3, memberCount); + + //Exclude.Start (Start,Stop] + memberCount = redisSortedSetStudy.SortedSetLengthByValue(defaultRedisKey, "first", "four", Exclude.Start, CommandFlags.None); + Assert.Equal(2, memberCount); - //todo:排序规则,还不清楚 + //Exclude.Stop [Start,Stop) + memberCount = redisSortedSetStudy.SortedSetLengthByValue(defaultRedisKey, "first", "four", Exclude.Stop, CommandFlags.None); + Assert.Equal(2, memberCount); + + //Exclude.Both (Start,Stop) + memberCount = redisSortedSetStudy.SortedSetLengthByValue(defaultRedisKey, "first", "four", Exclude.Both, CommandFlags.None); + Assert.Equal(1, memberCount); + } + + /// + /// 分数相同,字典排序,逐字符比较(汉字的比较等待确认) + /// 字典顺序(”0”<…<”9”<”A”<…<”Z”<”a”<…<”z”) + /// + [Fact] + public void SortedSetLengthByValueTest() + { SortedSetEntry[] sortedSetEntries = new SortedSetEntry[] { new SortedSetEntry("Andy",0), @@ -255,43 +287,44 @@ namespace RedisStudyTest new SortedSetEntry("remove",0), new SortedSetEntry("101",0), new SortedSetEntry("304",0), + new SortedSetEntry("404",0), new SortedSetEntry("王高峰",0), new SortedSetEntry("刘山东",0), }; redisSortedSetStudy.SortedSetAdd(defaultRedisKey, sortedSetEntries); - //默认:Exclude.None [Start,Stop] - var memberCount = redisSortedSetStudy.SortedSetLengthByValue(defaultRedisKey, "1", "B", Exclude.None, CommandFlags.None); - Assert.Equal(4, memberCount); + //数字排序 + var memberCount = redisSortedSetStudy.SortedSetLengthByValue(defaultRedisKey, "0", "5"); + Assert.Equal(3, memberCount); - ////Exclude.Start (Start,Stop] - //memberCount = redisSortedSetStudy.SortedSetLengthByValue(defaultRedisKey, 2, 4, Exclude.Start, CommandFlags.None); - //Assert.Equal(2, memberCount); + memberCount = redisSortedSetStudy.SortedSetLengthByValue(defaultRedisKey, "10", "4"); + Assert.Equal(2, memberCount); - ////Exclude.Stop [Start,Stop) - //memberCount = redisSortedSetStudy.SortedSetLengthByValue(defaultRedisKey, 2, 4, Exclude.Stop, CommandFlags.None); - //Assert.Equal(2, memberCount); + memberCount = redisSortedSetStudy.SortedSetLengthByValue(defaultRedisKey, "11", "40"); + Assert.Equal(1, memberCount); - ////Exclude.Both (Start,Stop) - //memberCount = redisSortedSetStudy.SortedSetLengthByValue(defaultRedisKey, 2, 4, Exclude.Both, CommandFlags.None); - //Assert.Equal(1, memberCount); - } + //字母排序 + memberCount = redisSortedSetStudy.SortedSetLengthByValue(defaultRedisKey, "And", "color"); + //And Andy Banana and color + Assert.Equal(5, memberCount); - [Fact] - public void SortedSetLengthByValueTest() - { - SortedSetEntry[] sortedSetEntries = new SortedSetEntry[] - { - new SortedSetEntry("first",1), - new SortedSetEntry("second",2), - new SortedSetEntry("third",3), - new SortedSetEntry("four",4), - new SortedSetEntry("five",5), - }; - redisSortedSetStudy.SortedSetAdd(defaultRedisKey, sortedSetEntries); + memberCount = redisSortedSetStudy.SortedSetLengthByValue(defaultRedisKey, "A", "color"); + //And Andy Banana and color + Assert.Equal(5, memberCount); - var memberCount = redisSortedSetStudy.SortedSetLength(defaultRedisKey, 1, 5); - Assert.Equal(sortedSetEntries.Length, memberCount); + memberCount = redisSortedSetStudy.SortedSetLengthByValue(defaultRedisKey, "A", "B"); + //And Andy 不包括Banana,因为Ba排在B后 + Assert.Equal(2, memberCount); + + memberCount = redisSortedSetStudy.SortedSetLengthByValue(defaultRedisKey, "A", "Bb"); + //And Andy Banana + Assert.Equal(3, memberCount); + + //汉字排序(转码后比较,转码规则不清楚) + //TODO:汉字排序规则不清楚) + memberCount = redisSortedSetStudy.SortedSetLengthByValue(defaultRedisKey, "王", "赵"); + //王高峰 + Assert.Equal(1, memberCount); } #endregion