Skip to content

Commit 484f581

Browse files
Node: Add FT._ALIASLIST command (#2652)
* Node: Add FT._ALIASLIST command --------- Signed-off-by: Prateek Kumar <[email protected]>
1 parent 76c6a4e commit 484f581

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#### Changes
2+
* Node: Add FT._ALIASLIST command([#2652](https://github.com/valkey-io/valkey-glide/pull/2652))
23
* Python: Python: `FT._ALIASLIST` command added([#2638](https://github.com/valkey-io/valkey-glide/pull/2638))
34
* Node: alias commands added: FT.ALIASADD, FT.ALIADDEL, FT.ALIASUPDATE([#2596](https://github.com/valkey-io/valkey-glide/pull/2596))
45
* Python code cleanup ([#2573](https://github.com/valkey-io/valkey-glide/pull/2573))

node/src/server-modules/GlideFt.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,29 @@ export class GlideFt {
698698
decoder: Decoder.String,
699699
}) as Promise<"OK">;
700700
}
701+
702+
/**
703+
* List the index aliases.
704+
*
705+
* @param client - The client to execute the command.
706+
* @param options - (Optional) See {@link DecoderOption}.
707+
* @returns A map of index aliases for indices being aliased.
708+
*
709+
* @example
710+
* ```typescript
711+
* // Example usage of FT._ALIASLIST to query index aliases
712+
* const result = await GlideFt.aliaslist(client);
713+
* console.log(result); // Output:
714+
* //[{"key": "alias1", "value": "index1"}, {"key": "alias2", "value": "index2"}]
715+
* ```
716+
*/
717+
static async aliaslist(
718+
client: GlideClient | GlideClusterClient,
719+
options?: DecoderOption,
720+
): Promise<GlideRecord<GlideString>> {
721+
const args: GlideString[] = ["FT._ALIASLIST"];
722+
return _handleCustomCommand(client, args, options);
723+
}
701724
}
702725

703726
/**

node/tests/ServerModules.test.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import {
1919
GlideClusterClient,
2020
GlideFt,
2121
GlideJson,
22+
GlideRecord,
23+
GlideString,
2224
InfoOptions,
2325
JsonGetOptions,
2426
ProtocolVersion,
@@ -3235,5 +3237,66 @@ describe("Server Module Tests", () => {
32353237
newIndex,
32363238
);
32373239
});
3240+
3241+
it("FT._ALIASLIST test", async () => {
3242+
client = await GlideClusterClient.createClient(
3243+
getClientConfigurationOption(
3244+
cluster.getAddresses(),
3245+
ProtocolVersion.RESP3,
3246+
),
3247+
);
3248+
const index1 = uuidv4();
3249+
const alias1 = uuidv4() + "-alias";
3250+
const index2 = uuidv4();
3251+
const alias2 = uuidv4() + "-alias";
3252+
3253+
//Create the 2 test indexes.
3254+
expect(
3255+
await GlideFt.create(client, index1, [
3256+
{ type: "NUMERIC", name: "published_at" },
3257+
{ type: "TAG", name: "category" },
3258+
]),
3259+
).toEqual("OK");
3260+
expect(
3261+
await GlideFt.create(client, index2, [
3262+
{ type: "NUMERIC", name: "published_at" },
3263+
{ type: "TAG", name: "category" },
3264+
]),
3265+
).toEqual("OK");
3266+
3267+
//Check if the two indexes created successfully.
3268+
expect(await client.customCommand(["FT._LIST"])).toContain(index1);
3269+
expect(await client.customCommand(["FT._LIST"])).toContain(index2);
3270+
3271+
//Add aliases to the 2 indexes.
3272+
expect(await GlideFt.aliasadd(client, index1, alias1)).toBe("OK");
3273+
expect(await GlideFt.aliasadd(client, index2, alias2)).toBe("OK");
3274+
3275+
//Test if the aliaslist command return the added alias.
3276+
const result = await GlideFt.aliaslist(client);
3277+
const expected: GlideRecord<GlideString> = [
3278+
{
3279+
key: alias2,
3280+
value: index2,
3281+
},
3282+
{
3283+
key: alias1,
3284+
value: index1,
3285+
},
3286+
];
3287+
3288+
const compareFunction = function (
3289+
a: { key: GlideString; value: GlideString },
3290+
b: { key: GlideString; value: GlideString },
3291+
) {
3292+
return a.key.toString().localeCompare(b.key.toString()) > 0
3293+
? 1
3294+
: -1;
3295+
};
3296+
3297+
expect(result.sort(compareFunction)).toEqual(
3298+
expected.sort(compareFunction),
3299+
);
3300+
});
32383301
});
32393302
});

0 commit comments

Comments
 (0)