Skip to content

Commit

Permalink
Node: Add FT._ALIASLIST command (#2652)
Browse files Browse the repository at this point in the history
* Node: Add FT._ALIASLIST command

---------

Signed-off-by: Prateek Kumar <prateek.kumar@improving.com>
  • Loading branch information
prateek-kumar-improving authored Nov 8, 2024
1 parent 76c6a4e commit 484f581
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#### Changes
* Node: Add FT._ALIASLIST command([#2652](https://github.com/valkey-io/valkey-glide/pull/2652))
* Python: Python: `FT._ALIASLIST` command added([#2638](https://github.com/valkey-io/valkey-glide/pull/2638))
* Node: alias commands added: FT.ALIASADD, FT.ALIADDEL, FT.ALIASUPDATE([#2596](https://github.com/valkey-io/valkey-glide/pull/2596))
* Python code cleanup ([#2573](https://github.com/valkey-io/valkey-glide/pull/2573))
Expand Down
23 changes: 23 additions & 0 deletions node/src/server-modules/GlideFt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,29 @@ export class GlideFt {
decoder: Decoder.String,
}) as Promise<"OK">;
}

/**
* List the index aliases.
*
* @param client - The client to execute the command.
* @param options - (Optional) See {@link DecoderOption}.
* @returns A map of index aliases for indices being aliased.
*
* @example
* ```typescript
* // Example usage of FT._ALIASLIST to query index aliases
* const result = await GlideFt.aliaslist(client);
* console.log(result); // Output:
* //[{"key": "alias1", "value": "index1"}, {"key": "alias2", "value": "index2"}]
* ```
*/
static async aliaslist(
client: GlideClient | GlideClusterClient,
options?: DecoderOption,
): Promise<GlideRecord<GlideString>> {
const args: GlideString[] = ["FT._ALIASLIST"];
return _handleCustomCommand(client, args, options);
}
}

/**
Expand Down
63 changes: 63 additions & 0 deletions node/tests/ServerModules.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {
GlideClusterClient,
GlideFt,
GlideJson,
GlideRecord,
GlideString,
InfoOptions,
JsonGetOptions,
ProtocolVersion,
Expand Down Expand Up @@ -3235,5 +3237,66 @@ describe("Server Module Tests", () => {
newIndex,
);
});

it("FT._ALIASLIST test", async () => {
client = await GlideClusterClient.createClient(
getClientConfigurationOption(
cluster.getAddresses(),
ProtocolVersion.RESP3,
),
);
const index1 = uuidv4();
const alias1 = uuidv4() + "-alias";
const index2 = uuidv4();
const alias2 = uuidv4() + "-alias";

//Create the 2 test indexes.
expect(
await GlideFt.create(client, index1, [
{ type: "NUMERIC", name: "published_at" },
{ type: "TAG", name: "category" },
]),
).toEqual("OK");
expect(
await GlideFt.create(client, index2, [
{ type: "NUMERIC", name: "published_at" },
{ type: "TAG", name: "category" },
]),
).toEqual("OK");

//Check if the two indexes created successfully.
expect(await client.customCommand(["FT._LIST"])).toContain(index1);
expect(await client.customCommand(["FT._LIST"])).toContain(index2);

//Add aliases to the 2 indexes.
expect(await GlideFt.aliasadd(client, index1, alias1)).toBe("OK");
expect(await GlideFt.aliasadd(client, index2, alias2)).toBe("OK");

//Test if the aliaslist command return the added alias.
const result = await GlideFt.aliaslist(client);
const expected: GlideRecord<GlideString> = [
{
key: alias2,
value: index2,
},
{
key: alias1,
value: index1,
},
];

const compareFunction = function (
a: { key: GlideString; value: GlideString },
b: { key: GlideString; value: GlideString },
) {
return a.key.toString().localeCompare(b.key.toString()) > 0
? 1
: -1;
};

expect(result.sort(compareFunction)).toEqual(
expected.sort(compareFunction),
);
});
});
});

0 comments on commit 484f581

Please sign in to comment.