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

added clientGetName command- Node #387

Merged
merged 1 commit into from
Oct 4, 2023
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
4 changes: 4 additions & 0 deletions node/src/Commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ export function createSelect(index: number): redis_request.Command {
return createCommand(RequestType.Select, [index.toString()]);
}

export function createClientGetName(): redis_request.Command {
return createCommand(RequestType.ClientGetName, []);
}

export function createConfigRewrite(): redis_request.Command {
return createCommand(RequestType.ConfigRewrite, []);
}
Expand Down
11 changes: 11 additions & 0 deletions node/src/RedisClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as net from "net";
import { BaseClient, ConnectionOptions, ReturnType } from "./BaseClient";
import {
InfoOptions,
createClientGetName,
createConfigGet,
createConfigResetStat,
createConfigRewrite,
Expand Down Expand Up @@ -127,6 +128,16 @@ export class RedisClient extends BaseClient {
return this.createWritePromise(createSelect(index));
}

/** Get the name of the current connection.
* See https://redis.io/commands/client-getname/ for more details.
*
* @returns the name of the client connection as a string if a name is set,
* or null if no name is assigned.
*/
public clientGetName(): Promise<string | null> {
return this.createWritePromise(createClientGetName());
}

/** Rewrite the configuration file with the current configuration.
* See https://redis.io/commands/config-rewrite/ for details.
*
Expand Down
26 changes: 26 additions & 0 deletions node/src/RedisClusterClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as net from "net";
import { BaseClient, ConnectionOptions, ReturnType } from "./BaseClient";
import {
InfoOptions,
createClientGetName,
createConfigGet,
createConfigResetStat,
createConfigRewrite,
Expand Down Expand Up @@ -233,6 +234,31 @@ export class RedisClusterClient extends BaseClient {
});
}

/** Get the name of the current connection.
* See https://redis.io/commands/client-getname/ for more details.
*
* @param route - The command will be routed automatically, unless `route` is provided, in which
* case the client will initially try to route the command to the nodes defined by `route`.
*
* @returns - the name of the client connection as a string if a name is set, or null if no name is assigned.
* When specifying a route other than a single node, it returns a dictionary where each address is the key and
* its corresponding node response is the value.
*/
public clientGetName(
route?: Routes
): Promise<ClusterResponse<string | null>> {
const result = this.createWritePromise<string | null>(
createClientGetName(),
toProtobufRoute(route)
);
return result.then((res) => {
return convertMultiNodeResponseToDict<string | null>(
res,
(response) => typeof response == "string" || response == null
);
});
}

/** Rewrite the configuration file with the current configuration.
* See https://redis.io/commands/config-rewrite/ for details.
*
Expand Down
14 changes: 10 additions & 4 deletions node/src/Transaction.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
InfoOptions,
SetOptions,
createClientGetName,
createConfigGet,
createConfigResetStat,
createConfigRewrite,
Expand Down Expand Up @@ -105,6 +106,15 @@ export class BaseTransaction {
this.commands.push(createDel(keys));
}

/** Get the name of the current connection.
* See https://redis.io/commands/client-getname/ for more details.
*
* Command Response - the name of the client connection as a string if a name is set, or null if no name is assigned.
*/
public clientGetName() {
this.commands.push(createClientGetName());
}

/** Rewrite the configuration file with the current configuration.
* See https://redis.io/commands/select/ for details.
*
Expand Down Expand Up @@ -215,8 +225,6 @@ export class BaseTransaction {
* See https://redis.io/commands/config-get/ for details.
*
* @param parameters - A list of configuration parameter names to retrieve values for.
* @param route - The command will be routed automatically, unless `route` is provided, in which
* case the client will initially try to route the command to the nodes defined by `route`.
*
* Returns A list of values corresponding to the configuration parameters.
*
Expand All @@ -229,8 +237,6 @@ export class BaseTransaction {
* See https://redis.io/commands/config-set/ for details.
*
* @param parameters - A List of keyValuePairs consisting of configuration parameters and their respective values to set.
* @param route - The command will be routed automatically, unless `route` is provided, in which
* case the client will initially try to route the command to the nodes defined by `route`.
*
* Returns "OK" when the configuration was set properly. Otherwise an error is raised.
*
Expand Down
11 changes: 11 additions & 0 deletions node/tests/SharedTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type BaseClient = {
ping: (str?: string) => Promise<string>;
get: (key: string) => Promise<string | null>;
del: (keys: string[]) => Promise<number>;
clientGetName: () => Promise<ClusterResponse<string | null>>;
configRewrite: () => Promise<"OK">;
info(options?: InfoOptions[]): Promise<ClusterResponse<string>>;
configResetStat: () => Promise<"OK">;
Expand Down Expand Up @@ -219,6 +220,16 @@ export function runBaseTests<Context>(config: {
config.timeout
);

it(
"testing clientGetName",
async () => {
await runTest(async (client: BaseClient) => {
expect(await client.clientGetName()).toBeNull();
});
},
config.timeout
);

it(
"test config rewrite",
async () => {
Expand Down