-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Adds support for XPENDING IDLE parameter #2822
Open
david-brink-talogy
wants to merge
3
commits into
StackExchange:main
Choose a base branch
from
david-brink-talogy:feature/xpending_idle
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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 |
---|---|---|
|
@@ -2803,7 +2803,10 @@ public Task<StreamPendingInfo> StreamPendingAsync(RedisKey key, RedisValue group | |
return ExecuteAsync(msg, ResultProcessor.StreamPendingInfo); | ||
} | ||
|
||
public StreamPendingMessageInfo[] StreamPendingMessages(RedisKey key, RedisValue groupName, int count, RedisValue consumerName, RedisValue? minId = null, RedisValue? maxId = null, CommandFlags flags = CommandFlags.None) | ||
public StreamPendingMessageInfo[] StreamPendingMessages(RedisKey key, RedisValue groupName, int count, RedisValue consumerName, RedisValue? minId = null, RedisValue? maxId = null, CommandFlags flags = CommandFlags.None) => | ||
StreamPendingMessages(key, groupName, count, consumerName, minId, maxId, null, flags); | ||
|
||
public StreamPendingMessageInfo[] StreamPendingMessages(RedisKey key, RedisValue groupName, int count, RedisValue consumerName, RedisValue? minId = null, RedisValue? maxId = null, long? minIdleTimeInMs = null, CommandFlags flags = CommandFlags.None) | ||
{ | ||
var msg = GetStreamPendingMessagesMessage( | ||
key, | ||
|
@@ -2812,12 +2815,16 @@ public StreamPendingMessageInfo[] StreamPendingMessages(RedisKey key, RedisValue | |
maxId, | ||
count, | ||
consumerName, | ||
minIdleTimeInMs, | ||
flags); | ||
|
||
return ExecuteSync(msg, ResultProcessor.StreamPendingMessages, defaultValue: Array.Empty<StreamPendingMessageInfo>()); | ||
} | ||
|
||
public Task<StreamPendingMessageInfo[]> StreamPendingMessagesAsync(RedisKey key, RedisValue groupName, int count, RedisValue consumerName, RedisValue? minId = null, RedisValue? maxId = null, CommandFlags flags = CommandFlags.None) | ||
public Task<StreamPendingMessageInfo[]> StreamPendingMessagesAsync(RedisKey key, RedisValue groupName, int count, RedisValue consumerName, RedisValue? minId = null, RedisValue? maxId = null, CommandFlags flags = CommandFlags.None) => | ||
StreamPendingMessagesAsync(key, groupName, count, consumerName, minId, maxId, null, flags); | ||
|
||
public Task<StreamPendingMessageInfo[]> StreamPendingMessagesAsync(RedisKey key, RedisValue groupName, int count, RedisValue consumerName, RedisValue? minId = null, RedisValue? maxId = null, long? minIdleTimeInMs = null, CommandFlags flags = CommandFlags.None) | ||
{ | ||
var msg = GetStreamPendingMessagesMessage( | ||
key, | ||
|
@@ -2826,6 +2833,7 @@ public Task<StreamPendingMessageInfo[]> StreamPendingMessagesAsync(RedisKey key, | |
maxId, | ||
count, | ||
consumerName, | ||
minIdleTimeInMs, | ||
flags); | ||
|
||
return ExecuteAsync(msg, ResultProcessor.StreamPendingMessages, defaultValue: Array.Empty<StreamPendingMessageInfo>()); | ||
|
@@ -4300,9 +4308,9 @@ private Message GetStreamCreateConsumerGroupMessage(RedisKey key, RedisValue gro | |
/// Gets a message for <see href="https://redis.io/commands/xpending/"/>. | ||
/// </summary> | ||
/// <remarks><seealso href="https://redis.io/topics/streams-intro"/></remarks> | ||
private Message GetStreamPendingMessagesMessage(RedisKey key, RedisValue groupName, RedisValue? minId, RedisValue? maxId, int count, RedisValue consumerName, CommandFlags flags) | ||
private Message GetStreamPendingMessagesMessage(RedisKey key, RedisValue groupName, RedisValue? minId, RedisValue? maxId, int count, RedisValue consumerName, long? minIdleTimeInMs, CommandFlags flags) | ||
{ | ||
// > XPENDING mystream mygroup - + 10 [consumer name] | ||
// > XPENDING mystream mygroup [IDLE min-idle-time] - + 10 [consumer name] | ||
// 1) 1) 1526569498055 - 0 | ||
// 2) "Bob" | ||
// 3) (integer)74170458 | ||
|
@@ -4316,16 +4324,33 @@ private Message GetStreamPendingMessagesMessage(RedisKey key, RedisValue groupNa | |
throw new ArgumentOutOfRangeException(nameof(count), "count must be greater than 0."); | ||
} | ||
|
||
var values = new RedisValue[consumerName == RedisValue.Null ? 4 : 5]; | ||
var valuesLength = 4; | ||
if (consumerName != RedisValue.Null) | ||
{ | ||
valuesLength++; | ||
} | ||
|
||
values[0] = groupName; | ||
values[1] = minId ?? StreamConstants.ReadMinValue; | ||
values[2] = maxId ?? StreamConstants.ReadMaxValue; | ||
values[3] = count; | ||
if (minIdleTimeInMs is not null) | ||
{ | ||
valuesLength += 2; | ||
} | ||
var values = new RedisValue[valuesLength]; | ||
|
||
var offset = 0; | ||
|
||
values[offset++] = groupName; | ||
if (minIdleTimeInMs is not null) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
{ | ||
values[offset++] = "IDLE"; | ||
values[offset++] = minIdleTimeInMs; | ||
} | ||
values[offset++] = minId ?? StreamConstants.ReadMinValue; | ||
values[offset++] = maxId ?? StreamConstants.ReadMaxValue; | ||
values[offset++] = count; | ||
|
||
if (consumerName != RedisValue.Null) | ||
{ | ||
values[4] = consumerName; | ||
values[offset++] = consumerName; | ||
} | ||
|
||
return Message.Create( | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
we need to add an overload here, i.e. a second method with different parameters; otherwise, this is a hard binary break - we try very hard not to do that. If the compiler complains about two methods with optional parameters, we can work around that
(yes: technically adding methods to the interface is also problematic, but: it is problematic in different ways, and in reality we don't expect custom implementations of the
IDatabase
etc APIs)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.
+1 on this. I'd leave the existing public method signatures as-is, and add new methods with additional required params as needed.