From 86796b7123538204991c0e0802b0c1417b4e34c7 Mon Sep 17 00:00:00 2001 From: bicijinlian Date: Mon, 2 Jul 2018 14:44:45 +0800 Subject: [PATCH] sorted set study --- RedisStudyTest/RedisSortedSetStudyTest.cs | 71 ++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) diff --git a/RedisStudyTest/RedisSortedSetStudyTest.cs b/RedisStudyTest/RedisSortedSetStudyTest.cs index 3be8c9d..13328db 100644 --- a/RedisStudyTest/RedisSortedSetStudyTest.cs +++ b/RedisStudyTest/RedisSortedSetStudyTest.cs @@ -166,7 +166,7 @@ namespace RedisStudyTest } #endregion - #region MyRegion + #region SortedSetLength [Fact] public void SortedSetLength_NotKey_Test() @@ -227,6 +227,75 @@ namespace RedisStudyTest #endregion + #region SortedSetLengthByValue 分数相同则字典排序 + + [Fact] + public void SortedSetLengthByValue_NotKey_Test() + { + var memberCount = redisSortedSetStudy.SortedSetLengthByValue(defaultRedisKey,1,200); + Assert.Equal(0, memberCount); + } + + /// + /// 排它性参数Exclude设置 测试 + /// + [Fact] + public void SortedSetLengthByValue_Exclude_Test() + { + + //todo:排序规则,还不清楚 + SortedSetEntry[] sortedSetEntries = new SortedSetEntry[] + { + new SortedSetEntry("Andy",0), + new SortedSetEntry("and",0), + new SortedSetEntry("And",0), + new SortedSetEntry("Banana",0), + new SortedSetEntry("color",0), + new SortedSetEntry("query",0), + new SortedSetEntry("remove",0), + new SortedSetEntry("101",0), + new SortedSetEntry("304",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); + + ////Exclude.Start (Start,Stop] + //memberCount = redisSortedSetStudy.SortedSetLengthByValue(defaultRedisKey, 2, 4, Exclude.Start, CommandFlags.None); + //Assert.Equal(2, memberCount); + + ////Exclude.Stop [Start,Stop) + //memberCount = redisSortedSetStudy.SortedSetLengthByValue(defaultRedisKey, 2, 4, Exclude.Stop, CommandFlags.None); + //Assert.Equal(2, memberCount); + + ////Exclude.Both (Start,Stop) + //memberCount = redisSortedSetStudy.SortedSetLengthByValue(defaultRedisKey, 2, 4, Exclude.Both, CommandFlags.None); + //Assert.Equal(1, 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); + + var memberCount = redisSortedSetStudy.SortedSetLength(defaultRedisKey, 1, 5); + Assert.Equal(sortedSetEntries.Length, memberCount); + } + + #endregion + #region 清理 public void Dispose() {