-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for BZMPOP, BZPOPMIN and BZPOPMAX
Add support for the BZMPOP, BZPOPMIN, BZPOPMAX commands. Issues #232, #233 and #234. These commands are blocking on the server, so they go against the current policy of the StackExchange.Redis library. Therefore make it obvious in the code documentation that attention must be given to the timeout in the connection multiplexer, client-side. The StackExchange.Redis library already defines a type for the payload returned by BZMPOP (which is the same as for ZMPOP), namely the SortedSetPopResult class. However, the constructor of that class is internal in the library, so we can't create instances of it. Therefore roll our out type for a <value, score> pair, and use Tuple to pair a key with a list of such <value, score> pairs. Instead of using Order to signal from which end of the sorted set to pop, define a MinMaxModifier enum, which more clearly expresses the intention and maps directly to the Redis command being executed.
- Loading branch information
Showing
8 changed files
with
603 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using StackExchange.Redis; | ||
|
||
namespace NRedisStack.Core.DataTypes; | ||
|
||
/// <summary> | ||
/// Modifier that can be used for sorted set commands, where a MIN/MAX argument is expected by the Redis server. | ||
/// </summary> | ||
public enum MinMaxModifier | ||
{ | ||
/// <summary> | ||
/// Maps to the <c>MIN</c> argument on the Redis server. | ||
/// </summary> | ||
Min, | ||
|
||
/// <summary> | ||
/// Maps to the <c>MAX</c> argument on the Redis server. | ||
/// </summary> | ||
Max | ||
} | ||
|
||
/// <summary> | ||
/// Conversion methods from/to other common data types. | ||
/// </summary> | ||
public static class MinMaxModifierExtensions | ||
{ | ||
/// <summary> | ||
/// Convert from <see cref="Order"/> to <see cref="MinMaxModifier"/>. | ||
/// </summary> | ||
public static MinMaxModifier ToMinMax(this Order order) => order switch | ||
{ | ||
Order.Ascending => MinMaxModifier.Min, | ||
Order.Descending => MinMaxModifier.Max, | ||
_ => throw new ArgumentOutOfRangeException(nameof(order)) | ||
}; | ||
} |
31 changes: 31 additions & 0 deletions
31
src/NRedisStack/CoreCommands/DataTypes/RedisValueWithScore.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using StackExchange.Redis; | ||
|
||
namespace NRedisStack.Core.DataTypes; | ||
|
||
/// <summary> | ||
/// Holds a <see cref="RedisValue"/> with an associated score. | ||
/// Used when working with sorted sets. | ||
/// </summary> | ||
public struct RedisValueWithScore | ||
{ | ||
/// <summary> | ||
/// Pair a <see cref="RedisValue"/> with a numeric score. | ||
/// </summary> | ||
public RedisValueWithScore(RedisValue value, double score) | ||
{ | ||
Value = value; | ||
Score = score; | ||
} | ||
|
||
/// <summary> | ||
/// The value of an item stored in a sorted set. For example, in the Redis command | ||
/// <c>ZADD my-set 5.1 my-value</c>, the value is <c>my-value</c>. | ||
/// </summary> | ||
public RedisValue Value { get; } | ||
|
||
/// <summary> | ||
/// The score of an item stored in a sorted set. For example, in the Redis command | ||
/// <c>ZADD my-set 5.1 my-value</c>, the score is <c>5.1</c>. | ||
/// </summary> | ||
public double Score { get; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
namespace NRedisStack.Core.Literals | ||
{ | ||
internal class CoreArgs | ||
internal static class CoreArgs | ||
{ | ||
public const string COUNT = "COUNT"; | ||
public const string lib_name = "LIB-NAME"; | ||
public const string lib_ver = "LIB-VER"; | ||
public const string MAX = "MAX"; | ||
public const string MIN = "MIN"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.