-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support GT, LT and CH in ZADD command (#2136)
[SortedSetAdd](https://redis.io/commands/zadd/) currently not supporting GT and LT features. Co-authored-by: Nick Craver <nrcraver@gmail.com>
- Loading branch information
1 parent
e0d8320
commit 67297e3
Showing
14 changed files
with
402 additions
and
92 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System; | ||
|
||
namespace StackExchange.Redis | ||
{ | ||
/// <summary> | ||
/// Indicates when this operation should be performed (only some variations are legal in a given context). | ||
/// </summary> | ||
[Flags] | ||
public enum SortedSetWhen | ||
{ | ||
/// <summary> | ||
/// The operation won't be prevented. | ||
/// </summary> | ||
Always = 0, | ||
/// <summary> | ||
/// The operation should only occur when there is an existing value. | ||
/// </summary> | ||
Exists = 1 << 0, | ||
/// <summary> | ||
/// The operation should only occur when the new score is greater than the current score. | ||
/// </summary> | ||
GreaterThan = 1 << 1, | ||
/// <summary> | ||
/// The operation should only occur when the new score is less than the current score. | ||
/// </summary> | ||
LessThan = 1 << 2, | ||
/// <summary> | ||
/// The operation should only occur when there is not an existing value. | ||
/// </summary> | ||
NotExists = 1 << 3, | ||
} | ||
|
||
internal static class SortedSetWhenExtensions | ||
{ | ||
internal static uint CountBits(this SortedSetWhen when) | ||
{ | ||
uint v = (uint)when; | ||
v -= ((v >> 1) & 0x55555555); // reuse input as temporary | ||
v = (v & 0x33333333) + ((v >> 2) & 0x33333333); // temp | ||
uint c = ((v + (v >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; // count | ||
return c; | ||
} | ||
|
||
internal static SortedSetWhen Parse(When when)=> when switch | ||
{ | ||
When.Always => SortedSetWhen.Always, | ||
When.Exists => SortedSetWhen.Exists, | ||
When.NotExists => SortedSetWhen.NotExists, | ||
_ => throw new ArgumentOutOfRangeException(nameof(when)) | ||
}; | ||
} | ||
} |
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
Oops, something went wrong.