Skip to content
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: added echo command. #1010

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions node/src/BaseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
createDecr,
createDecrBy,
createDel,
createEcho,
createExists,
createExpire,
createExpireAt,
Expand Down Expand Up @@ -1138,6 +1139,16 @@ export class BaseClient {
return this.createWritePromise(createZpopmax(key, count));
}

/** Echoes the provided `message` back.
* See https://redis.io/commands/echo for more details.
*
* @param message - The message to be echoed back.
* @returns The provided `message`.
*/
public echo(message: string): Promise<string> {
return this.createWritePromise(createEcho(message));
}

private readonly MAP_READ_FROM_STRATEGY: Record<
ReadFrom,
connection_request.ReadFrom
Expand Down
7 changes: 7 additions & 0 deletions node/src/Commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -863,3 +863,10 @@ export function createZpopmax(key: string, count?: number): redis_request.Comman
const args: string[] = count == undefined ? [key] : [key, count.toString()];
return createCommand(RequestType.ZPopMax, args);
}

/**
* @internal
*/
export function createEcho(message: string): redis_request.Command {
return createCommand(RequestType.Echo, [message]);
}
12 changes: 12 additions & 0 deletions node/src/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
createDecr,
createDecrBy,
createDel,
createEcho,
createExists,
createExpire,
createExpireAt,
Expand Down Expand Up @@ -900,6 +901,17 @@ export class BaseTransaction<T extends BaseTransaction<T>> {
return this.addAndReturn(createZpopmax(key, count));
}

/** Echoes the provided `message` back.
* See https://redis.io/commands/echo for more details.
*
* @param message - The message to be echoed back.
*
* Command Response - The provided `message`.
*/
public echo(message: string): T {
return this.addAndReturn(createEcho(message));
}

/** Executes a single command, without checking inputs. Every part of the command, including subcommands,
* should be added as a separate value in args.
*
Expand Down
11 changes: 11 additions & 0 deletions node/tests/SharedTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1532,6 +1532,17 @@ export function runBaseTests<Context>(config: {
config.timeout
);

it.each([ProtocolVersion.RESP2, ProtocolVersion.RESP3])(
`echo test_%p`,
async (protocol) => {
await runTest(async (client: BaseClient) => {
const message = uuidv4();
expect(await client.echo(message)).toEqual(message);
}, protocol);
},
config.timeout
);

it.each([ProtocolVersion.RESP2, ProtocolVersion.RESP3])(
`strlen test_%p`,
async (protocol) => {
Expand Down
2 changes: 2 additions & 0 deletions node/tests/TestUtilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ export function transactionTest(
args.push("OK");
baseTransaction.type(key1);
args.push("string");
baseTransaction.echo(value);
args.push(value);
baseTransaction.set(key2, "baz", {
returnOldValue: true,
});
Expand Down
Loading