|
|
|
@ -329,6 +329,85 @@ namespace RedisStudyTest
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region SortedSetRank
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void SortedSetRank_NotKey_Test()
|
|
|
|
|
{
|
|
|
|
|
var index = redisSortedSetStudy.SortedSetRank(defaultRedisKey, "first");
|
|
|
|
|
|
|
|
|
|
Assert.Null(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void SortedSetRankTest()
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
long? memberRank = null;
|
|
|
|
|
memberRank = redisSortedSetStudy.SortedSetRank(defaultRedisKey, "first");
|
|
|
|
|
Assert.Equal(0, memberRank);
|
|
|
|
|
|
|
|
|
|
memberRank = redisSortedSetStudy.SortedSetRank(defaultRedisKey, "second");
|
|
|
|
|
Assert.Equal(1, memberRank);
|
|
|
|
|
|
|
|
|
|
memberRank = redisSortedSetStudy.SortedSetRank(defaultRedisKey, "third");
|
|
|
|
|
Assert.Equal(2, memberRank);
|
|
|
|
|
|
|
|
|
|
memberRank = redisSortedSetStudy.SortedSetRank(defaultRedisKey, "four");
|
|
|
|
|
Assert.Equal(3, memberRank);
|
|
|
|
|
|
|
|
|
|
memberRank = redisSortedSetStudy.SortedSetRank(defaultRedisKey, "five");
|
|
|
|
|
Assert.Equal(4, memberRank);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region SortedSetRangeByRank
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void SortedSetRangeByRank_NotKey_Test()
|
|
|
|
|
{
|
|
|
|
|
var members = redisSortedSetStudy.SortedSetRangeByRank(defaultRedisKey);
|
|
|
|
|
Assert.Empty(members);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void SortedSetRangeByRankTest()
|
|
|
|
|
{
|
|
|
|
|
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 members = redisSortedSetStudy.SortedSetRangeByRank(defaultRedisKey);
|
|
|
|
|
Assert.NotEmpty(members);
|
|
|
|
|
for (var i=0; i< sortedSetEntries.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
Assert.Equal(sortedSetEntries[0].Element, members[0]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
members = redisSortedSetStudy.SortedSetRangeByRank(defaultRedisKey, 1, -1, Order.Descending, CommandFlags.None);
|
|
|
|
|
//four third second first
|
|
|
|
|
Assert.Equal(sortedSetEntries[3].Element, members[0]);
|
|
|
|
|
Assert.Equal(sortedSetEntries[2].Element, members[1]);
|
|
|
|
|
Assert.Equal(sortedSetEntries[1].Element, members[2]);
|
|
|
|
|
Assert.Equal(sortedSetEntries[0].Element, members[3]);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 清理
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|