Commit c7870e00 authored by Marc Gravell's avatar Marc Gravell

fix #880 - missing zrevrangebylex; note that to avoid confusion this...

fix #880 - missing zrevrangebylex; note that to avoid confusion this automatically adjusts to inverted parameter min/max usage, just like zrangebyscore already does
parent 1aeee1ca
......@@ -42,6 +42,13 @@ public void QueryRangeAndLengthByLex()
set = db.SortedSetRangeByValue(key, "aaa", "g", Exclude.Stop, 1, 3);
Equate(set, set.Length, "c", "d", "e");
set = db.SortedSetRangeByValue(key, "aaa", "g", Exclude.Stop, Order.Descending, 1, 3);
Equate(set, set.Length, "e", "d", "c");
set = db.SortedSetRangeByValue(key, "g", "aaa", Exclude.Start, Order.Descending, 1, 3);
Equate(set, set.Length, "e", "d", "c");
}
}
......
......@@ -193,6 +193,7 @@ internal enum RedisCommand
ZREMRANGEBYRANK,
ZREMRANGEBYSCORE,
ZREVRANGE,
ZREVRANGEBYLEX,
ZREVRANGEBYSCORE,
ZREVRANK,
ZSCAN,
......
......@@ -1303,10 +1303,33 @@ public interface IDatabase : IRedis, IDatabaseAsync
/// <param name="flags">The flags to use for this operation.</param>
/// <remarks>https://redis.io/commands/zrangebylex</remarks>
/// <returns>list of elements in the specified score range.</returns>
RedisValue[] SortedSetRangeByValue(RedisKey key,
RedisValue min,
RedisValue max,
Exclude exclude,
long skip,
long take = -1,
CommandFlags flags = CommandFlags.None); // defaults removed to avoid ambiguity with overload with order
/// <summary>
/// When all the elements in a sorted set are inserted with the same score, in order to force lexicographical ordering, this command returns all the elements in the sorted set at key with a value between min and max.
/// </summary>
/// <param name="key">The key of the sorted set.</param>
/// <param name="min">The min value to filter by.</param>
/// <param name="max">The max value to filter by.</param>
/// <param name="exclude">Which of <paramref name="min"/> and <paramref name="max"/> to exclude (defaults to both inclusive).</param>
/// <param name="order">Whether to order the data ascending or descending</param>
/// <param name="skip">How many items to skip.</param>
/// <param name="take">How many items to take.</param>
/// <param name="flags">The flags to use for this operation.</param>
/// <remarks>https://redis.io/commands/zrangebylex</remarks>
/// <remarks>https://redis.io/commands/zrevrangebylex</remarks>
/// <returns>list of elements in the specified score range.</returns>
RedisValue[] SortedSetRangeByValue(RedisKey key,
RedisValue min = default(RedisValue),
RedisValue max = default(RedisValue),
Exclude exclude = Exclude.None,
Order order = Order.Ascending,
long skip = 0,
long take = -1,
CommandFlags flags = CommandFlags.None);
......
......@@ -1242,10 +1242,33 @@ public interface IDatabaseAsync : IRedisAsync
/// <param name="flags">The flags to use for this operation.</param>
/// <remarks>https://redis.io/commands/zrangebylex</remarks>
/// <returns>list of elements in the specified score range.</returns>
Task<RedisValue[]> SortedSetRangeByValueAsync(RedisKey key,
RedisValue min,
RedisValue max,
Exclude exclude,
long skip,
long take = -1,
CommandFlags flags = CommandFlags.None); // defaults removed to avoid ambiguity with overload with order
/// <summary>
/// When all the elements in a sorted set are inserted with the same score, in order to force lexicographical ordering, this command returns all the elements in the sorted set at key with a value between min and max.
/// </summary>
/// <param name="key">The key of the sorted set.</param>
/// <param name="min">The min value to filter by.</param>
/// <param name="max">The max value to filter by.</param>
/// <param name="exclude">Which of <paramref name="min"/> and <paramref name="max"/> to exclude (defaults to both inclusive).</param>
/// <param name="order">Whether to order the data ascending or descending</param>
/// <param name="skip">How many items to skip.</param>
/// <param name="take">How many items to take.</param>
/// <param name="flags">The flags to use for this operation.</param>
/// <remarks>https://redis.io/commands/zrangebylex</remarks>
/// <remarks>https://redis.io/commands/zrevrangebylex</remarks>
/// <returns>list of elements in the specified score range.</returns>
Task<RedisValue[]> SortedSetRangeByValueAsync(RedisKey key,
RedisValue min = default(RedisValue),
RedisValue max = default(RedisValue),
Exclude exclude = Exclude.None,
Order order = Order.Ascending,
long skip = 0,
long take = -1,
CommandFlags flags = CommandFlags.None);
......
......@@ -561,7 +561,11 @@ public SortedSetEntry[] SortedSetRangeByScoreWithScores(RedisKey key, double sta
return Inner.SortedSetRangeByScoreWithScores(ToInner(key), start, stop, exclude, order, skip, take, flags);
}
public RedisValue[] SortedSetRangeByValue(RedisKey key, RedisValue min = default(RedisValue), RedisValue max = default(RedisValue), Exclude exclude = Exclude.None, long skip = 0, long take = -1, CommandFlags flags = CommandFlags.None)
public RedisValue[] SortedSetRangeByValue(RedisKey key, RedisValue min, RedisValue max, Exclude exclude, long skip, long take, CommandFlags flags)
{
return Inner.SortedSetRangeByValue(ToInner(key), min, max, exclude, Order.Ascending, skip, take, flags);
}
public RedisValue[] SortedSetRangeByValue(RedisKey key, RedisValue min = default(RedisValue), RedisValue max = default(RedisValue), Exclude exclude = Exclude.None, Order order = Order.Ascending, long skip = 0, long take = -1, CommandFlags flags = CommandFlags.None)
{
return Inner.SortedSetRangeByValue(ToInner(key), min, max, exclude, skip, take, flags);
}
......
......@@ -541,9 +541,14 @@ public Task<SortedSetEntry[]> SortedSetRangeByScoreWithScoresAsync(RedisKey key,
return Inner.SortedSetRangeByScoreWithScoresAsync(ToInner(key), start, stop, exclude, order, skip, take, flags);
}
public Task<RedisValue[]> SortedSetRangeByValueAsync(RedisKey key, RedisValue min = default(RedisValue), RedisValue max = default(RedisValue), Exclude exclude = Exclude.None, long skip = 0, long take = -1, CommandFlags flags = CommandFlags.None)
public Task<RedisValue[]> SortedSetRangeByValueAsync(RedisKey key, RedisValue min, RedisValue max, Exclude exclude, long skip, long take, CommandFlags flags)
{
return Inner.SortedSetRangeByValueAsync(ToInner(key), min, max, exclude, Order.Ascending, skip, take, flags);
}
public Task<RedisValue[]> SortedSetRangeByValueAsync(RedisKey key, RedisValue min = default(RedisValue), RedisValue max = default(RedisValue), Exclude exclude = Exclude.None, Order order = Order.Ascending, long skip = 0, long take = -1, CommandFlags flags = CommandFlags.None)
{
return Inner.SortedSetRangeByValueAsync(ToInner(key), min, max, exclude, skip, take, flags);
return Inner.SortedSetRangeByValueAsync(ToInner(key), min, max, exclude, order, skip, take, flags);
}
public Task<long?> SortedSetRankAsync(RedisKey key, RedisValue member, Order order = Order.Ascending, CommandFlags flags = CommandFlags.None)
......
......@@ -3057,9 +3057,29 @@ public long SortedSetLengthByValue(RedisKey key, RedisValue min, RedisValue max,
return ExecuteSync(msg, ResultProcessor.Int64);
}
public RedisValue[] SortedSetRangeByValue(RedisKey key, RedisValue min = default(RedisValue), RedisValue max = default(RedisValue), Exclude exclude = Exclude.None, long skip = 0, long take = -1, CommandFlags flags = CommandFlags.None)
public RedisValue[] SortedSetRangeByValue(RedisKey key, RedisValue min, RedisValue max, Exclude exclude, long skip, long take, CommandFlags flags)
=> SortedSetRangeByValue(key, min, max, exclude, Order.Ascending, skip, take, flags);
static void ReverseLimits(Order order, ref Exclude exclude, ref RedisValue start, ref RedisValue stop)
{
bool reverseLimits = (order == Order.Ascending) == start.CompareTo(stop) > 0;
if (reverseLimits)
{
var tmp = start;
start = stop;
stop = tmp;
switch (exclude)
{
case Exclude.Start: exclude = Exclude.Stop; break;
case Exclude.Stop: exclude = Exclude.Start; break;
}
}
}
public RedisValue[] SortedSetRangeByValue(RedisKey key, RedisValue min = default(RedisValue), RedisValue max = default(RedisValue),
Exclude exclude = Exclude.None, Order order = Order.Ascending, long skip = 0, long take = -1, CommandFlags flags = CommandFlags.None)
{
var msg = GetLexMessage(RedisCommand.ZRANGEBYLEX, key, min, max, exclude, skip, take, flags);
ReverseLimits(order, ref exclude, ref min, ref max);
var msg = GetLexMessage(order == Order.Ascending ? RedisCommand.ZRANGEBYLEX : RedisCommand.ZREVRANGEBYLEX, key, min, max, exclude, skip, take, flags);
return ExecuteSync(msg, ResultProcessor.RedisValueArray);
}
......@@ -3075,9 +3095,13 @@ public Task<long> SortedSetLengthByValueAsync(RedisKey key, RedisValue min, Redi
return ExecuteAsync(msg, ResultProcessor.Int64);
}
public Task<RedisValue[]> SortedSetRangeByValueAsync(RedisKey key, RedisValue min = default(RedisValue), RedisValue max = default(RedisValue), Exclude exclude = Exclude.None, long skip = 0, long take = -1, CommandFlags flags = CommandFlags.None)
public Task<RedisValue[]> SortedSetRangeByValueAsync(RedisKey key, RedisValue min, RedisValue max, Exclude exclude, long skip, long take, CommandFlags flags)
=> SortedSetRangeByValueAsync(key, min, max, exclude, Order.Ascending, skip, take, flags);
public Task<RedisValue[]> SortedSetRangeByValueAsync(RedisKey key, RedisValue min = default(RedisValue), RedisValue max = default(RedisValue),
Exclude exclude = Exclude.None, Order order = Order.Ascending, long skip = 0, long take = -1, CommandFlags flags = CommandFlags.None)
{
var msg = GetLexMessage(RedisCommand.ZRANGEBYLEX, key, min, max, exclude, skip, take, flags);
ReverseLimits(order, ref exclude, ref min, ref max);
var msg = GetLexMessage(order == Order.Ascending ? RedisCommand.ZRANGEBYLEX : RedisCommand.ZREVRANGEBYLEX, key, min, max, exclude, skip, take, flags);
return ExecuteAsync(msg, ResultProcessor.RedisValueArray);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment