-
Notifications
You must be signed in to change notification settings - Fork 53
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
Node: Add XINFO GROUPS
command.
#2122
Merged
Yury-Fridlyand
merged 6 commits into
valkey-io:main
from
Bit-Quill:node/yuryf-xinfo-groups-valkey-58
Aug 16, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1f71208
Add `XINFO GROUPS` command.
Yury-Fridlyand 7c8f44e
Signed-off-by: Yury-Fridlyand <[email protected]>
Yury-Fridlyand ac5ed8e
Signed-off-by: Yury-Fridlyand <[email protected]>
Yury-Fridlyand 9e60b8b
Apply suggestions from code review
Yury-Fridlyand 6c7867c
Merge branch 'main' into node/yuryf-xinfo-groups-valkey-58
Yury-Fridlyand ebdbf77
Update node/src/BaseClient.ts
Yury-Fridlyand 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5570,7 +5570,6 @@ export function runBaseTests<Context>(config: { | |
"last-entry": (string | number | string[])[]; | ||
groups: number; | ||
}; | ||
console.log(result); | ||
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. ❤️ |
||
|
||
// verify result: | ||
expect(result.length).toEqual(1); | ||
|
@@ -8232,6 +8231,197 @@ export function runBaseTests<Context>(config: { | |
config.timeout, | ||
); | ||
|
||
it.each([ProtocolVersion.RESP2, ProtocolVersion.RESP3])( | ||
`xinfogroups xinfo groups %p`, | ||
async (protocol) => { | ||
await runTest(async (client: BaseClient, cluster) => { | ||
const key = uuidv4(); | ||
const stringKey = uuidv4(); | ||
const groupName1 = uuidv4(); | ||
const consumer1 = uuidv4(); | ||
const streamId1 = "0-1"; | ||
const streamId2 = "0-2"; | ||
const streamId3 = "0-3"; | ||
|
||
expect( | ||
await client.xgroupCreate(key, groupName1, "0-0", { | ||
mkStream: true, | ||
}), | ||
).toEqual("OK"); | ||
|
||
// one empty group exists | ||
expect(await client.xinfoGroups(key)).toEqual( | ||
cluster.checkIfServerVersionLessThan("7.0.0") | ||
? [ | ||
{ | ||
name: groupName1, | ||
consumers: 0, | ||
pending: 0, | ||
"last-delivered-id": "0-0", | ||
}, | ||
] | ||
: [ | ||
{ | ||
name: groupName1, | ||
consumers: 0, | ||
pending: 0, | ||
"last-delivered-id": "0-0", | ||
"entries-read": null, | ||
lag: 0, | ||
}, | ||
], | ||
); | ||
|
||
expect( | ||
await client.xadd( | ||
key, | ||
[ | ||
["entry1_field1", "entry1_value1"], | ||
["entry1_field2", "entry1_value2"], | ||
], | ||
{ id: streamId1 }, | ||
), | ||
).toEqual(streamId1); | ||
|
||
expect( | ||
await client.xadd( | ||
key, | ||
[ | ||
["entry2_field1", "entry2_value1"], | ||
["entry2_field2", "entry2_value2"], | ||
], | ||
{ id: streamId2 }, | ||
), | ||
).toEqual(streamId2); | ||
|
||
expect( | ||
await client.xadd( | ||
key, | ||
[["entry3_field1", "entry3_value1"]], | ||
{ id: streamId3 }, | ||
), | ||
).toEqual(streamId3); | ||
|
||
// same as previous check, bug lag = 3, there are 3 messages unread | ||
expect(await client.xinfoGroups(key)).toEqual( | ||
cluster.checkIfServerVersionLessThan("7.0.0") | ||
? [ | ||
{ | ||
name: groupName1, | ||
consumers: 0, | ||
pending: 0, | ||
"last-delivered-id": "0-0", | ||
}, | ||
] | ||
: [ | ||
{ | ||
name: groupName1, | ||
consumers: 0, | ||
pending: 0, | ||
"last-delivered-id": "0-0", | ||
"entries-read": null, | ||
lag: 3, | ||
}, | ||
], | ||
); | ||
|
||
expect( | ||
await client.customCommand([ | ||
"XREADGROUP", | ||
"GROUP", | ||
groupName1, | ||
consumer1, | ||
"STREAMS", | ||
key, | ||
">", | ||
]), | ||
).toEqual({ | ||
[key]: { | ||
[streamId1]: [ | ||
["entry1_field1", "entry1_value1"], | ||
["entry1_field2", "entry1_value2"], | ||
], | ||
[streamId2]: [ | ||
["entry2_field1", "entry2_value1"], | ||
["entry2_field2", "entry2_value2"], | ||
], | ||
[streamId3]: [["entry3_field1", "entry3_value1"]], | ||
}, | ||
}); | ||
// after reading, `lag` is reset, and `pending`, consumer count and last ID are set | ||
expect(await client.xinfoGroups(key)).toEqual( | ||
cluster.checkIfServerVersionLessThan("7.0.0") | ||
? [ | ||
{ | ||
name: groupName1, | ||
consumers: 1, | ||
pending: 3, | ||
"last-delivered-id": streamId3, | ||
}, | ||
] | ||
: [ | ||
{ | ||
name: groupName1, | ||
consumers: 1, | ||
pending: 3, | ||
"last-delivered-id": streamId3, | ||
"entries-read": 3, | ||
lag: 0, | ||
}, | ||
], | ||
); | ||
|
||
expect( | ||
await client.customCommand([ | ||
"XACK", | ||
key, | ||
groupName1, | ||
streamId1, | ||
]), | ||
).toEqual(1); | ||
// once message ack'ed, pending counter decreased | ||
expect(await client.xinfoGroups(key)).toEqual( | ||
cluster.checkIfServerVersionLessThan("7.0.0") | ||
? [ | ||
{ | ||
name: groupName1, | ||
consumers: 1, | ||
pending: 2, | ||
"last-delivered-id": streamId3, | ||
}, | ||
] | ||
: [ | ||
{ | ||
name: groupName1, | ||
consumers: 1, | ||
pending: 2, | ||
"last-delivered-id": streamId3, | ||
"entries-read": 3, | ||
lag: 0, | ||
}, | ||
], | ||
); | ||
|
||
// key exists, but it is not a stream | ||
expect(await client.set(stringKey, "foo")).toEqual("OK"); | ||
await expect(client.xinfoGroups(stringKey)).rejects.toThrow( | ||
RequestError, | ||
); | ||
|
||
// Passing a non-existing key raises an error | ||
const key2 = uuidv4(); | ||
await expect(client.xinfoGroups(key2)).rejects.toThrow( | ||
RequestError, | ||
); | ||
// create a second stream | ||
await client.xadd(key2, [["a", "b"]]); | ||
// no group yet exists | ||
expect(await client.xinfoGroups(key2)).toEqual([]); | ||
}, protocol); | ||
}, | ||
config.timeout, | ||
); | ||
|
||
it.each([ProtocolVersion.RESP2, ProtocolVersion.RESP3])( | ||
`xpending test_%p`, | ||
async (protocol) => { | ||
|
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.
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.
confirm that this should be removed?
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 suppress this eslint check if we import a type to refer in docs.
KeyWeight
is used as a function argument, so we can remove it.