From b3727118fbae4fdb9842ba630ec0c1deed17b3c0 Mon Sep 17 00:00:00 2001 From: Craig Pastro Date: Sun, 21 Feb 2021 21:08:42 +0900 Subject: [PATCH] feat: Implement CLIENT GETREDIR (#191) --- command.ts | 6 ++++++ redis.ts | 4 ++++ tests/connection_test.ts | 15 +++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/command.ts b/command.ts index 7b704fe6..cdd8dd36 100644 --- a/command.ts +++ b/command.ts @@ -992,6 +992,12 @@ XRANGE somestream - + */ clientGetName(): Promise; + /** + * Returns the client ID we are redirecting our tracking notifications to. + * @see https://redis.io/commands/client-getredir + */ + clientGetRedir(): Promise; + /** * Returns the id of the current redis connection. */ diff --git a/redis.ts b/redis.ts index b4baabfa..a1a1f3a5 100644 --- a/redis.ts +++ b/redis.ts @@ -324,6 +324,10 @@ export class RedisImpl implements Redis { return this.execBulkReply("CLIENT", "GETNAME"); } + clientGetRedir() { + return this.execIntegerReply("CLIENT", "GETREDIR"); + } + clientID() { return this.execIntegerReply("CLIENT", "ID"); } diff --git a/tests/connection_test.ts b/tests/connection_test.ts index 23d86e70..afc69ef2 100644 --- a/tests/connection_test.ts +++ b/tests/connection_test.ts @@ -77,6 +77,21 @@ suite.test("client setname & getname", async () => { assertEquals(await client.clientGetName(), "deno-redis"); }); +suite.test("client getredir with no redirect", async () => { + assertEquals(await client.clientGetRedir(), -1); +}); + +suite.test("client getredir with redirect", async () => { + const tempClient = await newClient({ hostname: "127.0.0.1", port: 7003 }); + try { + const id = await tempClient.clientID(); + await client.clientTracking({ mode: "ON", redirect: id }); + assertEquals(await client.clientGetRedir(), id); + } finally { + tempClient.close(); + } +}); + suite.test("client pause", async () => { assertEquals(await client.clientPause(10), "OK"); });