SortedSet Test

master
bicijinlian 7 years ago
parent 86796b7123
commit cb74222185

@ -242,8 +242,40 @@ namespace RedisStudyTest
[Fact] [Fact]
public void SortedSetLengthByValue_Exclude_Test() 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);
}
/// <summary>
/// 分数相同,字典排序,逐字符比较(汉字的比较等待确认)
/// 字典顺序”0”<…<”9”<”A”<…<”Z”<”a”<…<”z”
/// </summary>
[Fact]
public void SortedSetLengthByValueTest()
{
SortedSetEntry[] sortedSetEntries = new SortedSetEntry[] SortedSetEntry[] sortedSetEntries = new SortedSetEntry[]
{ {
new SortedSetEntry("Andy",0), new SortedSetEntry("Andy",0),
@ -255,43 +287,44 @@ namespace RedisStudyTest
new SortedSetEntry("remove",0), new SortedSetEntry("remove",0),
new SortedSetEntry("101",0), new SortedSetEntry("101",0),
new SortedSetEntry("304",0), new SortedSetEntry("304",0),
new SortedSetEntry("404",0),
new SortedSetEntry("王高峰",0), new SortedSetEntry("王高峰",0),
new SortedSetEntry("刘山东",0), new SortedSetEntry("刘山东",0),
}; };
redisSortedSetStudy.SortedSetAdd(defaultRedisKey, sortedSetEntries); redisSortedSetStudy.SortedSetAdd(defaultRedisKey, sortedSetEntries);
//默认Exclude.None [Start,Stop] //数字排序
var memberCount = redisSortedSetStudy.SortedSetLengthByValue(defaultRedisKey, "1", "B", Exclude.None, CommandFlags.None); var memberCount = redisSortedSetStudy.SortedSetLengthByValue(defaultRedisKey, "0", "5");
Assert.Equal(4, memberCount); Assert.Equal(3, memberCount);
////Exclude.Start (Start,Stop] memberCount = redisSortedSetStudy.SortedSetLengthByValue(defaultRedisKey, "10", "4");
//memberCount = redisSortedSetStudy.SortedSetLengthByValue(defaultRedisKey, 2, 4, Exclude.Start, CommandFlags.None); Assert.Equal(2, memberCount);
//Assert.Equal(2, memberCount);
////Exclude.Stop [Start,Stop) memberCount = redisSortedSetStudy.SortedSetLengthByValue(defaultRedisKey, "11", "40");
//memberCount = redisSortedSetStudy.SortedSetLengthByValue(defaultRedisKey, 2, 4, Exclude.Stop, CommandFlags.None); Assert.Equal(1, memberCount);
//Assert.Equal(2, memberCount);
////Exclude.Both (Start,Stop) //字母排序
//memberCount = redisSortedSetStudy.SortedSetLengthByValue(defaultRedisKey, 2, 4, Exclude.Both, CommandFlags.None); memberCount = redisSortedSetStudy.SortedSetLengthByValue(defaultRedisKey, "And", "color");
//Assert.Equal(1, memberCount); //And Andy Banana and color
} Assert.Equal(5, memberCount);
[Fact] memberCount = redisSortedSetStudy.SortedSetLengthByValue(defaultRedisKey, "A", "color");
public void SortedSetLengthByValueTest() //And Andy Banana and color
{ Assert.Equal(5, memberCount);
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);
var memberCount = redisSortedSetStudy.SortedSetLength(defaultRedisKey, 1, 5); memberCount = redisSortedSetStudy.SortedSetLengthByValue(defaultRedisKey, "A", "B");
Assert.Equal(sortedSetEntries.Length, memberCount); //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 #endregion

Loading…
Cancel
Save