-
Notifications
You must be signed in to change notification settings - Fork 543
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Compatibility] Added BZMPOP, BZPOPMAX and BZPOPMIN commands #884
base: main
Are you sure you want to change the base?
[Compatibility] Added BZMPOP, BZPOPMAX and BZPOPMIN commands #884
Conversation
@@ -20,6 +20,12 @@ public CollectionItemResult(byte[] key, byte[][] items) | |||
Items = items; | |||
} | |||
|
|||
public CollectionItemResult(byte[] key, (double Score, byte[] Element)[] scoredItems) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to create a separate PR in future to remove CollectionItemResult
class and replace it with SpanByteAndMemory
, Let me know if there is any issue with that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why? It'd make the code less readable. I'd leave it as-is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice PR! Thanks for the contribution. Added a few comments.
@@ -6,6 +6,7 @@ | |||
using System.Collections.Generic; | |||
using System.Diagnostics; | |||
using System.Linq; | |||
using System.Runtime.Intrinsics.X86; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mistake?
@@ -886,6 +887,19 @@ private void SortedSetRank(ref ObjectInput input, ref SpanByteAndMemory output, | |||
} | |||
} | |||
|
|||
public (double Score, byte[] Element) Pop(bool popMaxScoreElement = false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add an XML comment
@@ -886,6 +887,19 @@ private void SortedSetRank(ref ObjectInput input, ref SpanByteAndMemory output, | |||
} | |||
} | |||
|
|||
public (double Score, byte[] Element) Pop(bool popMaxScoreElement = false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should rename this to PopMinOrMax for clarity
@@ -2,6 +2,7 @@ | |||
// Licensed under the MIT license. | |||
|
|||
using System; | |||
using System.Linq; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary using
keysBytes[i] = parseState.GetArgSliceByRef(i).SpanByte.ToByteArray(); | ||
} | ||
|
||
if (!parseState.TryGetDouble(parseState.Count - 1, out var timeout)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could do this verification (as well as the itemBroker one) before the keysBytes allocation
} | ||
else | ||
{ | ||
_ = EXPIRE(destinationKey, TimeSpan.Zero, out _, StoreType.Object, ExpireOption.None, | ||
ref lockableContext, ref objectContext); | ||
} | ||
|
||
itemBroker.HandleCollectionUpdate(destinationKeyBty); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about SortedSetUnionStore & SortedSetIntersectStore?
@@ -10,7 +10,7 @@ | |||
|
|||
namespace Garnet.test | |||
{ | |||
public class RespBlockingListTests | |||
public class RespBlockingTests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
naming: RespBlockingCollectionTests might be a bit more informative
@@ -20,6 +20,12 @@ public CollectionItemResult(byte[] key, byte[][] items) | |||
Items = items; | |||
} | |||
|
|||
public CollectionItemResult(byte[] key, (double Score, byte[] Element)[] scoredItems) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why? It'd make the code less readable. I'd leave it as-is.
/// <summary> | ||
/// Scored items retrieved from collection, where each item has an associated score. | ||
/// </summary> | ||
internal (double Score, byte[] Element)[] ScoredItems { get; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think instead of doing this we should re-use the Item & Items properties to store the elements & have matching double Score and double[] Scores properties.
@@ -389,14 +389,154 @@ public void BlmpopBlockingWithCountTest() | |||
var pushingTask = taskFactory.StartNew(() => | |||
{ | |||
using var lcr = TestUtils.CreateRequest(); | |||
Task.Delay(TimeSpan.FromSeconds(2)).Wait(); | |||
Task.Delay(TimeSpan.FromSeconds(5)).Wait(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might want to choose smaller time constants here, as this affects the CI runtime
Adding the BZMPOP, BZPOPMAX and BZPOPMIN commands to garnet