Skip to content

Commit

Permalink
Node: Add command XGROUP SETID
Browse files Browse the repository at this point in the history
Signed-off-by: TJ Zhang <[email protected]>
  • Loading branch information
TJ Zhang committed Aug 19, 2024
1 parent 89b10d4 commit 453d546
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
* Node: Added BZPOPMAX & BZPOPMIN command ([#2077]((https://github.com/valkey-io/valkey-glide/pull/2077))
* Node: Added XGROUP CREATECONSUMER & XGROUP DELCONSUMER commands ([#2088](https://github.com/valkey-io/valkey-glide/pull/2088))
* Node: Added GETEX command ([#2107]((https://github.com/valkey-io/valkey-glide/pull/2107))
* Node: Added XGROUP SETID command ([#TBD]((https://github.com/valkey-io/valkey-glide/pull/TBD))

#### Breaking Changes
* Node: (Refactor) Convert classes to types ([#2005](https://github.com/valkey-io/valkey-glide/pull/2005))
Expand Down
31 changes: 31 additions & 0 deletions node/src/BaseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ import {
createZScan,
createZScore,
createZUnionStore,
createXGroupSetid,
} from "./Commands";
import {
ClosingError,
Expand Down Expand Up @@ -5036,6 +5037,36 @@ export class BaseClient {
preferReplica: connection_request.ReadFrom.PreferReplica,
};

/**
* Sets the last delivered ID for a consumer group.
*
* See https://valkey.io/commands/xgroup-setid for more details.
*
* since Valkey 7.0 and above
*
* @param key - The key of the stream.
* @param groupName - The consumer group name.
* @param id - The stream entry ID that should be set as the last delivered ID for the consumer
* group.
* @param entriesRead - (Optional) A value representing the number of stream entries already read by the group.
* @returns `OK`.
*
* * @example
* ```typescript
* console.log(await client.xgroupSetId("mystream", "mygroup", "0", 1L)); // Output is "OK"
* ```
*/
public async xgroupSetId(
key: string,
groupName: string,
id: string,
entriesRead?: number,
): Promise<string> {
return this.createWritePromise(
createXGroupSetid(key, groupName, id, entriesRead),
);
}

/** Returns the element at index `index` in the list stored at `key`.
* The index is zero-based, so 0 means the first element, 1 the second element and so on.
* Negative indices can be used to designate elements starting at the tail of the list.
Expand Down
18 changes: 18 additions & 0 deletions node/src/Commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3880,3 +3880,21 @@ export function createGetEx(

return createCommand(RequestType.GetEx, args);
}

/**
* @internal
*/
export function createXGroupSetid(
key: string,
groupName: string,
id: string,
entriesRead?: number,
): command_request.Command {
const args = [key, groupName, id];

if (entriesRead) {
args.push(entriesRead.toString());
}

return createCommand(RequestType.XGroupSetId, args);
}
27 changes: 27 additions & 0 deletions node/src/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ import {
createZScan,
createZScore,
createZUnionStore,
createXGroupSetid,
} from "./Commands";
import { command_request } from "./ProtobufMessage";

Expand Down Expand Up @@ -2765,6 +2766,32 @@ export class BaseTransaction<T extends BaseTransaction<T>> {
);
}

/**
* Sets the last delivered ID for a consumer group.
*
* See https://valkey.io/commands/xgroup-setid for more details.
*
* since Valkey 7.0 and above
*
* @param key - The key of the stream.
* @param groupName - The consumer group name.
* @param id - The stream entry ID that should be set as the last delivered ID for the consumer
* group.
* @param entriesRead - (Optional) A value representing the number of stream entries already read by the group.
*
* Command Response - "OK".
*/
public xgroupSetId(
key: string,
groupName: string,
id: string,
entriesRead?: number,
): T {
return this.addAndReturn(
createXGroupSetid(key, groupName, id, entriesRead),
);
}

/**
* Renames `key` to `newkey`.
* If `newkey` already exists it is overwritten.
Expand Down

0 comments on commit 453d546

Please sign in to comment.