Skip to content

Commit 324e246

Browse files
committed
Merge branch 'v5_to_master' into cmd-parser-with-commands
2 parents 82c6819 + 1dc6d8e commit 324e246

26 files changed

+463
-292
lines changed

packages/client/lib/client/index.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,33 @@ describe('Client', () => {
451451
assert.deepEqual(hash, results);
452452
}, GLOBAL.SERVERS.OPEN);
453453

454+
testUtils.testWithClient('hScanNoValuesIterator', async client => {
455+
const hash: Record<string, string> = {};
456+
const expectedFields: Array<string> = [];
457+
for (let i = 0; i < 100; i++) {
458+
hash[i.toString()] = i.toString();
459+
expectedFields.push(i.toString());
460+
}
461+
462+
await client.hSet('key', hash);
463+
464+
const actualFields: Array<string> = [];
465+
for await (const fields of client.hScanNoValuesIterator('key')) {
466+
for (const field of fields) {
467+
actualFields.push(field);
468+
}
469+
}
470+
471+
function sort(a: string, b: string) {
472+
return Number(a) - Number(b);
473+
}
474+
475+
assert.deepEqual(actualFields.sort(sort), expectedFields);
476+
}, {
477+
...GLOBAL.SERVERS.OPEN,
478+
minimumDockerVersion: [7, 4]
479+
});
480+
454481
testUtils.testWithClient('sScanIterator', async client => {
455482
const members = new Set<string>();
456483
for (let i = 0; i < 100; i++) {

packages/client/lib/client/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,19 @@ export default class RedisClient<
942942
} while (cursor !== '0');
943943
}
944944

945+
async* hScanNoValuesIterator(
946+
this: RedisClientType<M, F, S, RESP, TYPE_MAPPING>,
947+
key: RedisArgument,
948+
options?: ScanCommonOptions & ScanIteratorOptions
949+
) {
950+
let cursor = options?.cursor ?? '0';
951+
do {
952+
const reply = await this.hScanNoValues(key, cursor, options);
953+
cursor = reply.cursor;
954+
yield reply.fields;
955+
} while (cursor !== '0');
956+
}
957+
945958
async* sScanIterator(
946959
this: RedisClientType<M, F, S, RESP, TYPE_MAPPING>,
947960
key: RedisArgument,

packages/client/lib/commands/HEXPIRE.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
import { CommandParser } from '../client/parser';
2-
import { ArrayReply, Command, NumberReply, RedisArgument } from '../RESP/types';
2+
import { ArrayReply, Command, RedisArgument } from '../RESP/types';
33
import { RedisVariadicArgument } from './generic-transformers';
44

5+
export const HASH_EXPIRATION = {
6+
/** The field does not exist */
7+
FIELD_NOT_EXISTS: -2,
8+
/** Specified NX | XX | GT | LT condition not met */
9+
CONDITION_NOT_MET: 0,
10+
/** Expiration time was set or updated */
11+
UPDATED: 1,
12+
/** Field deleted because the specified expiration time is in the past */
13+
DELETED: 2
14+
} as const;
15+
16+
export type HashExpiration = typeof HASH_EXPIRATION[keyof typeof HASH_EXPIRATION];
17+
518
export default {
619
parseCommand(
720
parser: CommandParser,
@@ -22,5 +35,5 @@ export default {
2235

2336
parser.pushVariadicWithLength(fields);
2437
},
25-
transformReply: undefined as unknown as () => ArrayReply<NumberReply>
38+
transformReply: undefined as unknown as () => ArrayReply<HashExpiration>
2639
} as const satisfies Command;

packages/client/lib/commands/HPERSIST.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ export default {
1414
parser.pushVariadicWithLength(fields);
1515
},
1616
transformReply: undefined as unknown as () => ArrayReply<NumberReply> | NullReply
17-
} as const satisfies Command;
17+
} as const satisfies Command;

packages/client/lib/commands/HPEXPIRE.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { CommandParser } from '../client/parser';
2-
import { ArrayReply, Command, NullReply, NumberReply, RedisArgument } from '../RESP/types';
2+
import { ArrayReply, Command, NullReply, RedisArgument } from '../RESP/types';
33
import { RedisVariadicArgument } from './generic-transformers';
4+
import { HashExpiration } from "./HEXPIRE";
45

56
export default {
67
parseCommand(
@@ -22,5 +23,5 @@ export default {
2223

2324
parser.pushVariadicWithLength(fields);
2425
},
25-
transformReply: undefined as unknown as () => ArrayReply<NumberReply> | NullReply
26-
} as const satisfies Command;
26+
transformReply: undefined as unknown as () => ArrayReply<HashExpiration> | NullReply
27+
} as const satisfies Command;

packages/client/lib/commands/HPEXPIREAT.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { CommandParser } from '../client/parser';
2-
import { ArrayReply, Command, NullReply, NumberReply, RedisArgument } from '../RESP/types';
2+
import { ArrayReply, Command, NullReply, RedisArgument } from '../RESP/types';
33
import { RedisVariadicArgument, transformPXAT } from './generic-transformers';
4+
import { HashExpiration } from "./HEXPIRE";
45

56
export default {
67
IS_READ_ONLY: true,
@@ -23,5 +24,5 @@ export default {
2324

2425
parser.pushVariadicWithLength(fields);
2526
},
26-
transformReply: undefined as unknown as () => ArrayReply<NumberReply> | NullReply
27-
} as const satisfies Command;
27+
transformReply: undefined as unknown as () => ArrayReply<HashExpiration> | NullReply
28+
} as const satisfies Command;

packages/client/lib/commands/HPEXPIRETIME.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ export default {
1515
parser.pushVariadicWithLength(fields);
1616
},
1717
transformReply: undefined as unknown as () => ArrayReply<NumberReply> | NullReply
18-
} as const satisfies Command;
18+
} as const satisfies Command;

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,31 @@ describe('HSCAN', () => {
4141
});
4242
});
4343

44+
describe('transformReply', () => {
45+
it('without tuples', () => {
46+
assert.deepEqual(
47+
HSCAN.transformReply(['0' as any, []]),
48+
{
49+
cursor: '0',
50+
entries: []
51+
}
52+
);
53+
});
54+
55+
it('with tuples', () => {
56+
assert.deepEqual(
57+
HSCAN.transformReply(['0' as any, ['field', 'value'] as any]),
58+
{
59+
cursor: '0',
60+
entries: [{
61+
field: 'field',
62+
value: 'value'
63+
}]
64+
}
65+
);
66+
});
67+
});
68+
4469
testUtils.testWithClient('client.hScan', async client => {
4570
const [, reply] = await Promise.all([
4671
client.hSet('key', 'field', 'value'),

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import HSCAN_NOVALUES from './HSCAN_NOVALUES';
44
import { parseArgs } from './generic-transformers';
55

66
describe('HSCAN_NOVALUES', () => {
7-
testUtils.isVersionGreaterThanHook([7.4]);
7+
testUtils.isVersionGreaterThanHook([7,4]);
88

99
describe('transformArguments', () => {
1010
it('cusror only', () => {
@@ -43,6 +43,29 @@ describe('HSCAN_NOVALUES', () => {
4343
});
4444
});
4545

46+
describe('transformReply', () => {
47+
it('without keys', () => {
48+
assert.deepEqual(
49+
HSCAN_NOVALUES.transformReply(['0' as any, []]),
50+
{
51+
cursor: '0',
52+
fields: []
53+
}
54+
);
55+
});
56+
57+
it('with keys', () => {
58+
assert.deepEqual(
59+
HSCAN_NOVALUES.transformReply(['0' as any, ['key1', 'key2'] as any]),
60+
{
61+
cursor: '0',
62+
fields: ['key1', 'key2']
63+
}
64+
);
65+
});
66+
});
67+
68+
4669
testUtils.testWithClient('client.hScanNoValues', async client => {
4770
const [, reply] = await Promise.all([
4871
client.hSet('key', 'field', 'value'),

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ describe('AGGREGATE', () => {
2121
);
2222
});
2323

24+
it('with ADDSCORES', () => {
25+
assert.deepEqual(
26+
parseArgs(AGGREGATE, 'index', '*', { ADDSCORES: true }),
27+
['FT.AGGREGATE', 'index', '*', 'ADDSCORES']
28+
);
29+
});
30+
2431
describe('with LOAD', () => {
2532
describe('single', () => {
2633
describe('without alias', () => {

packages/search/lib/commands/AGGREGATE.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ interface FilterStep extends AggregateStep<FT_AGGREGATE_STEPS['FILTER']> {
119119

120120
export interface FtAggregateOptions {
121121
VERBATIM?: boolean;
122+
ADDSCORES?: boolean;
122123
LOAD?: LoadField | Array<LoadField>;
123124
TIMEOUT?: number;
124125
STEPS?: Array<GroupByStep | SortStep | ApplyStep | LimitStep | FilterStep>;
@@ -168,6 +169,10 @@ export function parseAggregateOptions(parser: CommandParser , options?: FtAggreg
168169
parser.push('VERBATIM');
169170
}
170171

172+
if (options?.ADDSCORES) {
173+
parser.push('ADDSCORES');
174+
}
175+
171176
if (options?.LOAD) {
172177
const args: Array<RedisArgument> = [];
173178

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,18 @@ describe('FT.CREATE', () => {
148148
['FT.CREATE', 'index', 'SCHEMA', 'field', 'TAG', 'WITHSUFFIXTRIE']
149149
);
150150
});
151+
152+
it('with INDEXEMPTY', () => {
153+
assert.deepEqual(
154+
parseArgs(CREATE, 'index', {
155+
field: {
156+
type: SCHEMA_FIELD_TYPE.TAG,
157+
INDEXEMPTY: true
158+
}
159+
}),
160+
['FT.CREATE', 'index', 'SCHEMA', 'field', 'TAG', 'INDEXEMPTY']
161+
);
162+
});
151163
});
152164

153165
describe('VECTOR', () => {
@@ -281,6 +293,18 @@ describe('FT.CREATE', () => {
281293
['FT.CREATE', 'index', 'SCHEMA', 'field', 'TEXT', 'NOINDEX']
282294
);
283295
});
296+
297+
it('with INDEXMISSING', () => {
298+
assert.deepEqual(
299+
parseArgs(CREATE, 'index', {
300+
field: {
301+
type: SCHEMA_FIELD_TYPE.TEXT,
302+
INDEXMISSING: true
303+
}
304+
}),
305+
['FT.CREATE', 'index', 'SCHEMA', 'field', 'TEXT', 'INDEXMISSING']
306+
);
307+
});
284308
});
285309

286310
it('with ON', () => {

0 commit comments

Comments
 (0)