@@ -3668,12 +3668,15 @@ private Message GetSortedSetMultiPopMessage(RedisKey[] keys, Order order, long c
36683668 return tran ;
36693669 }
36703670
3671- private static RedisValue GetLexRange ( RedisValue value , Exclude exclude , bool isStart )
3671+ private static RedisValue GetLexRange ( RedisValue value , Exclude exclude , bool isStart , Order order )
36723672 {
36733673 if ( value . IsNull )
36743674 {
3675- return isStart ? RedisLiterals . MinusSymbol : RedisLiterals . PlusSymbol ;
3675+ if ( order == Order . Ascending ) return isStart ? RedisLiterals . MinusSymbol : RedisLiterals . PlusSymbol ;
3676+
3677+ return isStart ? RedisLiterals . PlusSymbol : RedisLiterals . MinusSymbol ; // 24.01.2024: when descending order: Plus and Minus have to be reversed
36763678 }
3679+
36773680 byte [ ] orig = value ! ;
36783681
36793682 byte [ ] result = new byte [ orig . Length + 1 ] ;
@@ -4846,9 +4849,9 @@ private Message GetStringSetAndGetMessage(
48464849 return new ScanEnumerable < T > ( this , server , key , pattern , pageSize , cursor , pageOffset , flags , command , processor , noValues ) ;
48474850 }
48484851
4849- private Message GetLexMessage ( RedisCommand command , RedisKey key , RedisValue min , RedisValue max , Exclude exclude , long skip , long take , CommandFlags flags )
4852+ private Message GetLexMessage ( RedisCommand command , RedisKey key , RedisValue min , RedisValue max , Exclude exclude , long skip , long take , CommandFlags flags , Order order )
48504853 {
4851- RedisValue start = GetLexRange ( min , exclude , true ) , stop = GetLexRange ( max , exclude , false ) ;
4854+ RedisValue start = GetLexRange ( min , exclude , true , order ) , stop = GetLexRange ( max , exclude , false , order ) ;
48524855
48534856 if ( skip == 0 && take == - 1 )
48544857 return Message . Create ( Database , flags , command , key , start , stop ) ;
@@ -4858,7 +4861,7 @@ private Message GetLexMessage(RedisCommand command, RedisKey key, RedisValue min
48584861
48594862 public long SortedSetLengthByValue ( RedisKey key , RedisValue min , RedisValue max , Exclude exclude = Exclude . None , CommandFlags flags = CommandFlags . None )
48604863 {
4861- var msg = GetLexMessage ( RedisCommand . ZLEXCOUNT , key , min , max , exclude , 0 , - 1 , flags ) ;
4864+ var msg = GetLexMessage ( RedisCommand . ZLEXCOUNT , key , min , max , exclude , 0 , - 1 , flags , Order . Ascending ) ;
48624865 return ExecuteSync ( msg , ResultProcessor . Int64 ) ;
48634866 }
48644867
@@ -4891,19 +4894,19 @@ public RedisValue[] SortedSetRangeByValue(
48914894 CommandFlags flags = CommandFlags . None )
48924895 {
48934896 ReverseLimits ( order , ref exclude , ref min , ref max ) ;
4894- var msg = GetLexMessage ( order == Order . Ascending ? RedisCommand . ZRANGEBYLEX : RedisCommand . ZREVRANGEBYLEX , key , min , max , exclude , skip , take , flags ) ;
4897+ var msg = GetLexMessage ( order == Order . Ascending ? RedisCommand . ZRANGEBYLEX : RedisCommand . ZREVRANGEBYLEX , key , min , max , exclude , skip , take , flags , order ) ;
48954898 return ExecuteSync ( msg , ResultProcessor . RedisValueArray , defaultValue : Array . Empty < RedisValue > ( ) ) ;
48964899 }
48974900
48984901 public long SortedSetRemoveRangeByValue ( RedisKey key , RedisValue min , RedisValue max , Exclude exclude = Exclude . None , CommandFlags flags = CommandFlags . None )
48994902 {
4900- var msg = GetLexMessage ( RedisCommand . ZREMRANGEBYLEX , key , min , max , exclude , 0 , - 1 , flags ) ;
4903+ var msg = GetLexMessage ( RedisCommand . ZREMRANGEBYLEX , key , min , max , exclude , 0 , - 1 , flags , Order . Ascending ) ;
49014904 return ExecuteSync ( msg , ResultProcessor . Int64 ) ;
49024905 }
49034906
49044907 public Task < long > SortedSetLengthByValueAsync ( RedisKey key , RedisValue min , RedisValue max , Exclude exclude = Exclude . None , CommandFlags flags = CommandFlags . None )
49054908 {
4906- var msg = GetLexMessage ( RedisCommand . ZLEXCOUNT , key , min , max , exclude , 0 , - 1 , flags ) ;
4909+ var msg = GetLexMessage ( RedisCommand . ZLEXCOUNT , key , min , max , exclude , 0 , - 1 , flags , Order . Ascending ) ;
49074910 return ExecuteAsync ( msg , ResultProcessor . Int64 ) ;
49084911 }
49094912
@@ -4921,13 +4924,13 @@ public Task<RedisValue[]> SortedSetRangeByValueAsync(
49214924 CommandFlags flags = CommandFlags . None )
49224925 {
49234926 ReverseLimits ( order , ref exclude , ref min , ref max ) ;
4924- var msg = GetLexMessage ( order == Order . Ascending ? RedisCommand . ZRANGEBYLEX : RedisCommand . ZREVRANGEBYLEX , key , min , max , exclude , skip , take , flags ) ;
4927+ var msg = GetLexMessage ( order == Order . Ascending ? RedisCommand . ZRANGEBYLEX : RedisCommand . ZREVRANGEBYLEX , key , min , max , exclude , skip , take , flags , order ) ;
49254928 return ExecuteAsync ( msg , ResultProcessor . RedisValueArray , defaultValue : Array . Empty < RedisValue > ( ) ) ;
49264929 }
49274930
49284931 public Task < long > SortedSetRemoveRangeByValueAsync ( RedisKey key , RedisValue min , RedisValue max , Exclude exclude = Exclude . None , CommandFlags flags = CommandFlags . None )
49294932 {
4930- var msg = GetLexMessage ( RedisCommand . ZREMRANGEBYLEX , key , min , max , exclude , 0 , - 1 , flags ) ;
4933+ var msg = GetLexMessage ( RedisCommand . ZREMRANGEBYLEX , key , min , max , exclude , 0 , - 1 , flags , Order . Ascending ) ;
49314934 return ExecuteAsync ( msg , ResultProcessor . Int64 ) ;
49324935 }
49334936
0 commit comments