Skip to content
Open
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
56 changes: 56 additions & 0 deletions packages/search/lib/commands/ALIASLIST.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { strict as assert } from 'node:assert';
import testUtils, { GLOBAL } from '../test-utils';
import ALIASLIST from './ALIASLIST';
import { SCHEMA_FIELD_TYPE } from './CREATE';
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';

describe('FT.ALIASLIST', () => {
it('transformArguments', () => {
assert.deepEqual(
parseArgs(ALIASLIST, 'index'),
['FT.ALIASLIST', 'index']
);
});

testUtils.testWithClient('client.ft.aliasList on index without aliases', async client => {
const [, reply] = await Promise.all([
client.ft.create('index', {
field: SCHEMA_FIELD_TYPE.TEXT
}),
client.ft.aliasList('index')
]);

assert.deepEqual(reply, []);
}, { ...GLOBAL.SERVERS.OPEN, minimumDockerVersion: [8, 10] });

testUtils.testWithClient('client.ft.aliasList with aliases', async client => {
const [, , , reply] = await Promise.all([
client.ft.create('index', {
field: SCHEMA_FIELD_TYPE.TEXT
}),
client.ft.aliasAdd('alias1', 'index'),
client.ft.aliasAdd('alias2', 'index'),
client.ft.aliasList('index')
]);

// ordering is not part of the contract
assert.deepEqual(
[...reply].sort(),
['alias1', 'alias2']
);
}, { ...GLOBAL.SERVERS.OPEN, minimumDockerVersion: [8, 10] });

testUtils.testWithClient('client.ft.aliasList on missing index rejects with index-not-found', async client => {
await assert.rejects(
client.ft.aliasList('nonexistent'),
err => {
assert.ok(err instanceof Error);
assert.ok(
err.message.startsWith('SEARCH_INDEX_NOT_FOUND'),
`expected SEARCH_INDEX_NOT_FOUND prefix, got: ${err.message}`
);
return true;
}
);
}, { ...GLOBAL.SERVERS.OPEN, minimumDockerVersion: [8, 10] });
});
14 changes: 14 additions & 0 deletions packages/search/lib/commands/ALIASLIST.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { CommandParser } from '@redis/client/dist/lib/client/parser';
import { RedisArgument, ArrayReply, SetReply, BlobStringReply, Command } from '@redis/client/dist/lib/RESP/types';

export default {
NOT_KEYED_COMMAND: true,
IS_READ_ONLY: true,
parseCommand(parser: CommandParser, index: RedisArgument) {
parser.push('FT.ALIASLIST', index);
},
transformReply: {
2: undefined as unknown as () => ArrayReply<BlobStringReply>,
3: undefined as unknown as () => SetReply<BlobStringReply>
}
} as const satisfies Command;
11 changes: 11 additions & 0 deletions packages/search/lib/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import AGGREGATE_WITHCURSOR from './AGGREGATE_WITHCURSOR';
import AGGREGATE from './AGGREGATE';
import ALIASADD from './ALIASADD';
import ALIASDEL from './ALIASDEL';
import ALIASLIST from './ALIASLIST';
import ALIASUPDATE from './ALIASUPDATE';
import CONFIG_GET from './CONFIG_GET';
import CONFIG_SET from './CONFIG_SET';
Expand Down Expand Up @@ -121,6 +122,16 @@ export default {
* @param alias - The alias to remove
*/
aliasDel: ALIASDEL,
/**
* Lists all aliases associated with the given index.
* @param index - The index name whose aliases to list
*/
ALIASLIST,
/**
* Lists all aliases associated with the given index.
* @param index - The index name whose aliases to list
*/
aliasList: ALIASLIST,
/**
* Updates the index pointed to by an existing alias.
* @param alias - The existing alias to update
Expand Down