Skip to content

Commit f258b6e

Browse files
authored
feat: Implement CLIENT SETNAME & GETNAME (#177)
1 parent 660c347 commit f258b6e

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

command.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,11 +865,24 @@ XRANGE somestream - +
865865
): Promise<Integer>;
866866

867867
// Client
868+
/**
869+
* Returns the name of the current connection which can be set by `client_setname`.
870+
* @see https://redis.io/commands/client-getname
871+
*/
872+
client_getname(): Promise<Bulk>;
873+
868874
/**
869875
* Returns the id of the current redis connection.
870876
*/
871877
client_id(): Promise<Integer>;
872878

879+
/**
880+
* Sets a `connectionName` to the current connection.
881+
* You can get the name of the current connection using `client_getname()`.
882+
* @see https://redis.io/commands/client-setname
883+
*/
884+
client_setname(connectionName: string): Promise<Status>;
885+
873886
// Cluster
874887
cluster_addslots(...slots: number[]): Promise<Status>;
875888
cluster_countfailurereports(node_id: string): Promise<Integer>;

redis.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,18 @@ export class RedisImpl implements Redis {
283283
>;
284284
}
285285

286+
client_getname() {
287+
return this.execBulkReply("CLIENT", "GETNAME");
288+
}
289+
286290
client_id() {
287291
return this.execIntegerReply("CLIENT", "ID");
288292
}
289293

294+
client_setname(connectionName: string) {
295+
return this.execStatusReply("CLIENT", "SETNAME", connectionName);
296+
}
297+
290298
cluster_addslots(...slots: number[]) {
291299
return this.execStatusReply("CLUSTER", "ADDSLOTS", ...slots);
292300
}

tests/connection_test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,9 @@ suite.test("client id", async () => {
4242
assertEquals(typeof id, "number");
4343
});
4444

45+
suite.test("client setname & getname", async () => {
46+
assertEquals(await client.client_setname("deno-redis"), "OK");
47+
assertEquals(await client.client_getname(), "deno-redis");
48+
});
49+
4550
suite.runTests();

0 commit comments

Comments
 (0)