Skip to content

Commit 9f85da9

Browse files
committed
Merge branch 'master' of github.com:redis/node-redis
2 parents 9c66e91 + 4683e96 commit 9f85da9

22 files changed

+617
-258
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
fail-fast: false
1818
matrix:
1919
node-version: ['12', '14', '16']
20-
redis-version: ['5', '6.0', '6.2']
20+
redis-version: ['5', '6.0', '6.2', '7.0-rc2']
2121
steps:
2222
- uses: actions/[email protected]
2323
with:

packages/client/lib/commands/ACL_GETUSER.spec.ts

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,32 @@ describe('ACL GETUSER', () => {
1313
});
1414

1515
testUtils.testWithClient('client.aclGetUser', async client => {
16+
const expectedReply: any = {
17+
passwords: [],
18+
commands: '+@all',
19+
};
20+
21+
if (testUtils.isVersionGreaterThan([7])) {
22+
expectedReply.flags = ['on', 'nopass'];
23+
expectedReply.keys = '~*';
24+
expectedReply.channels = '&*';
25+
expectedReply.selectors = [];
26+
} else {
27+
expectedReply.keys = ['*'];
28+
expectedReply.selectors = undefined;
29+
30+
if (testUtils.isVersionGreaterThan([6, 2])) {
31+
expectedReply.flags = ['on', 'allkeys', 'allchannels', 'allcommands', 'nopass'];
32+
expectedReply.channels = ['*'];
33+
} else {
34+
expectedReply.flags = ['on', 'allkeys', 'allcommands', 'nopass'];
35+
expectedReply.channels = undefined;
36+
}
37+
}
38+
1639
assert.deepEqual(
1740
await client.aclGetUser('default'),
18-
{
19-
passwords: [],
20-
commands: '+@all',
21-
keys: ['*'],
22-
...(testUtils.isVersionGreaterThan([6, 2]) ? {
23-
flags: ['on', 'allkeys', 'allchannels', 'allcommands', 'nopass'],
24-
channels: ['*']
25-
} : {
26-
flags: ['on', 'allkeys', 'allcommands', 'nopass'],
27-
channels: undefined
28-
})
29-
}
41+
expectedReply
3042
);
3143
}, GLOBAL.SERVERS.OPEN);
3244
});

packages/client/lib/commands/ACL_GETUSER.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,27 @@ export function transformArguments(username: RedisCommandArgument): RedisCommand
55
}
66

77
type AclGetUserRawReply = [
8-
_: RedisCommandArgument,
9-
flags: Array<RedisCommandArgument>,
10-
_: RedisCommandArgument,
11-
passwords: Array<RedisCommandArgument>,
12-
_: RedisCommandArgument,
13-
commands: RedisCommandArgument,
14-
_: RedisCommandArgument,
15-
keys: Array<RedisCommandArgument>,
16-
_: RedisCommandArgument,
17-
channels: Array<RedisCommandArgument>
8+
'flags',
9+
Array<RedisCommandArgument>,
10+
'passwords',
11+
Array<RedisCommandArgument>,
12+
'commands',
13+
RedisCommandArgument,
14+
'keys',
15+
Array<RedisCommandArgument> | RedisCommandArgument,
16+
'channels',
17+
Array<RedisCommandArgument> | RedisCommandArgument,
18+
'selectors' | undefined,
19+
Array<Array<string>> | undefined
1820
];
1921

2022
interface AclUser {
2123
flags: Array<RedisCommandArgument>;
2224
passwords: Array<RedisCommandArgument>;
2325
commands: RedisCommandArgument;
24-
keys: Array<RedisCommandArgument>;
25-
channels: Array<RedisCommandArgument>
26+
keys: Array<RedisCommandArgument> | RedisCommandArgument;
27+
channels: Array<RedisCommandArgument> | RedisCommandArgument;
28+
selectors?: Array<Array<string>>;
2629
}
2730

2831
export function transformReply(reply: AclGetUserRawReply): AclUser {
@@ -31,6 +34,7 @@ export function transformReply(reply: AclGetUserRawReply): AclUser {
3134
passwords: reply[3],
3235
commands: reply[5],
3336
keys: reply[7],
34-
channels: reply[9]
37+
channels: reply[9],
38+
selectors: reply[11]
3539
};
3640
}

packages/client/lib/commands/BITCOUNT.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function transformArguments(
2222
range.end.toString()
2323
);
2424

25-
if (range?.mode) {
25+
if (range.mode) {
2626
args.push(range.mode);
2727
}
2828
}

packages/client/lib/commands/COMMAND_INFO.spec.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ export function assertPingCommand(commandInfo: CommandReply | null | undefined):
99
{
1010
name: 'ping',
1111
arity: -1,
12-
flags: new Set([CommandFlags.STALE, CommandFlags.FAST]),
12+
flags: new Set(
13+
testUtils.isVersionGreaterThan([7]) ?
14+
[CommandFlags.FAST] :
15+
[CommandFlags.STALE, CommandFlags.FAST]
16+
),
1317
firstKeyIndex: 0,
1418
lastKeyIndex: 0,
1519
step: 0,

packages/search/lib/commands/AGGREGATE.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,26 @@ describe('AGGREGATE', () => {
434434
);
435435
});
436436
});
437+
438+
it('with PARAMS', () => {
439+
assert.deepEqual(
440+
transformArguments('index', '*', {
441+
PARAMS: {
442+
param: 'value'
443+
}
444+
}),
445+
['FT.AGGREGATE', 'index', '*', 'PARAMS', '2', 'param', 'value']
446+
);
447+
});
448+
449+
it('with DIALECT', () => {
450+
assert.deepEqual(
451+
transformArguments('index', '*', {
452+
DIALECT: 1
453+
}),
454+
['FT.AGGREGATE', 'index', '*', 'DIALECT', '1']
455+
);
456+
});
437457
});
438458

439459
testUtils.testWithClient('client.ft.aggregate', async client => {

packages/search/lib/commands/AGGREGATE.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { RedisCommandArgument, RedisCommandArguments } from '@node-redis/client/dist/lib/commands';
22
import { pushVerdictArgument, transformTuplesReply } from '@node-redis/client/dist/lib/commands/generic-transformers';
3-
import { PropertyName, pushArgumentsWithLength, pushSortByArguments, SortByProperty } from '.';
3+
import { Params, PropertyName, pushArgumentsWithLength, pushParamsArgs, pushSortByArguments, SortByProperty } from '.';
44

55
export enum AggregateSteps {
66
GROUPBY = 'GROUPBY',
@@ -122,24 +122,25 @@ export interface AggregateOptions {
122122
VERBATIM?: true;
123123
LOAD?: LoadField | Array<LoadField>;
124124
STEPS?: Array<GroupByStep | SortStep | ApplyStep | LimitStep | FilterStep>;
125+
PARAMS?: Params;
126+
DIALECT?: number;
125127
}
126128

127129
export function transformArguments(
128130
index: string,
129131
query: string,
130132
options?: AggregateOptions
131133
): RedisCommandArguments {
132-
133-
const args = ['FT.AGGREGATE', index, query];
134-
pushAggregatehOptions(args, options);
135-
return args;
134+
return pushAggregatehOptions(
135+
['FT.AGGREGATE', index, query],
136+
options
137+
);
136138
}
137139

138140
export function pushAggregatehOptions(
139141
args: RedisCommandArguments,
140142
options?: AggregateOptions
141143
): RedisCommandArguments {
142-
143144
if (options?.VERBATIM) {
144145
args.push('VERBATIM');
145146
}
@@ -202,6 +203,12 @@ export function pushAggregatehOptions(
202203
}
203204
}
204205

206+
pushParamsArgs(args, options?.PARAMS);
207+
208+
if (options?.DIALECT) {
209+
args.push('DIALECT', options.DIALECT.toString());
210+
}
211+
205212
return args;
206213
}
207214

@@ -257,7 +264,6 @@ function pushGroupByReducer(args: RedisCommandArguments, reducer: GroupByReducer
257264
}
258265
}
259266
});
260-
261267
break;
262268
}
263269

packages/search/lib/commands/CREATE.spec.ts

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { strict as assert } from 'assert';
22
import testUtils, { GLOBAL } from '../test-utils';
33
import { transformArguments } from './CREATE';
4-
import { SchemaFieldTypes, SchemaTextFieldPhonetics, RedisSearchLanguages } from '.';
4+
import { SchemaFieldTypes, SchemaTextFieldPhonetics, RedisSearchLanguages, VectorAlgorithms } from '.';
55

66
describe('CREATE', () => {
77
describe('transformArguments', () => {
@@ -126,6 +126,52 @@ describe('CREATE', () => {
126126
});
127127
});
128128

129+
describe('VECTOR', () => {
130+
it('Flat algorithm', () => {
131+
assert.deepEqual(
132+
transformArguments('index', {
133+
field: {
134+
type: SchemaFieldTypes.VECTOR,
135+
ALGORITHM: VectorAlgorithms.FLAT,
136+
TYPE: 'FLOAT32',
137+
DIM: 2,
138+
DISTANCE_METRIC: 'L2',
139+
INITIAL_CAP: 1000000,
140+
BLOCK_SIZE: 1000
141+
}
142+
}),
143+
[
144+
'FT.CREATE', 'index', 'SCHEMA', 'field', 'VECTOR', 'FLAT', '10', 'TYPE',
145+
'FLOAT32', 'DIM', '2', 'DISTANCE_METRIC', 'L2', 'INITIAL_CAP', '1000000',
146+
'BLOCK_SIZE', '1000'
147+
]
148+
);
149+
});
150+
151+
it('HNSW algorithm', () => {
152+
assert.deepEqual(
153+
transformArguments('index', {
154+
field: {
155+
type: SchemaFieldTypes.VECTOR,
156+
ALGORITHM: VectorAlgorithms.HNSW,
157+
TYPE: 'FLOAT32',
158+
DIM: 2,
159+
DISTANCE_METRIC: 'L2',
160+
INITIAL_CAP: 1000000,
161+
M: 40,
162+
EF_CONSTRUCTION: 250,
163+
EF_RUNTIME: 20
164+
}
165+
}),
166+
[
167+
'FT.CREATE', 'index', 'SCHEMA', 'field', 'VECTOR', 'HNSW', '14', 'TYPE',
168+
'FLOAT32', 'DIM', '2', 'DISTANCE_METRIC', 'L2', 'INITIAL_CAP', '1000000',
169+
'M', '40', 'EF_CONSTRUCTION', '250', 'EF_RUNTIME', '20'
170+
]
171+
);
172+
});
173+
});
174+
129175
describe('with generic options', () => {
130176
it('with AS', () => {
131177
assert.deepEqual(

packages/search/lib/commands/EXPLAIN.spec.ts

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,32 @@ import { strict as assert } from 'assert';
22
import { transformArguments } from './EXPLAIN';
33

44
describe('EXPLAIN', () => {
5-
it('transformArguments', () => {
6-
assert.deepEqual(
7-
transformArguments('index', '*'),
8-
['FT.EXPLAIN', 'index', '*']
9-
);
5+
describe('transformArguments', () => {
6+
it('simple', () => {
7+
assert.deepEqual(
8+
transformArguments('index', '*'),
9+
['FT.EXPLAIN', 'index', '*']
10+
);
11+
});
12+
13+
it('with PARAMS', () => {
14+
assert.deepEqual(
15+
transformArguments('index', '*', {
16+
PARAMS: {
17+
param: 'value'
18+
}
19+
}),
20+
['FT.EXPLAIN', 'index', '*', 'PARAMS', '2', 'param', 'value']
21+
);
22+
});
23+
24+
it('with DIALECT', () => {
25+
assert.deepEqual(
26+
transformArguments('index', '*', {
27+
DIALECT: 1
28+
}),
29+
['FT.EXPLAIN', 'index', '*', 'DIALECT', '1']
30+
);
31+
});
1032
});
1133
});
Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
1+
import { Params, pushParamsArgs } from ".";
2+
13
export const IS_READ_ONLY = true;
24

3-
export function transformArguments(index: string, query: string): Array<string> {
4-
return ['FT.EXPLAIN', index, query];
5+
interface ExplainOptions {
6+
PARAMS?: Params;
7+
DIALECT?: number;
8+
}
9+
10+
export function transformArguments(
11+
index: string,
12+
query: string,
13+
options?: ExplainOptions
14+
): Array<string> {
15+
const args = ['FT.EXPLAIN', index, query];
16+
17+
pushParamsArgs(args, options?.PARAMS);
18+
19+
if (options?.DIALECT) {
20+
args.push('DIALECT', options.DIALECT.toString());
21+
}
22+
23+
return args;
524
}
625

726
export declare function transformReply(): string;

0 commit comments

Comments
 (0)