Skip to content

Commit 37be30a

Browse files
committed
some more commands
1 parent 442a554 commit 37be30a

32 files changed

+545
-612
lines changed
Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,34 @@
11
import { strict as assert } from 'assert';
22
import testUtils, { GLOBAL } from '../test-utils';
3-
import { transformArguments } from './LCS_IDX';
3+
import LCS_IDX from './LCS_IDX';
44

5-
describe('LCS_IDX', () => {
6-
testUtils.isVersionGreaterThanHook([7]);
5+
describe('LCS IDX', () => {
6+
testUtils.isVersionGreaterThanHook([7]);
77

8-
it('transformArguments', () => {
9-
assert.deepEqual(
10-
transformArguments('1', '2'),
11-
['LCS', '1', '2', 'IDX']
12-
);
13-
});
8+
it('transformArguments', () => {
9+
assert.deepEqual(
10+
LCS_IDX.transformArguments('1', '2'),
11+
['LCS', '1', '2', 'IDX']
12+
);
13+
});
1414

15-
testUtils.testWithClient('client.lcsIdx', async client => {
16-
const [, reply] = await Promise.all([
17-
client.mSet({
18-
'1': 'abc',
19-
'2': 'bc'
20-
}),
21-
client.lcsIdx('1', '2')
22-
]);
15+
testUtils.testWithClient('client.lcsIdx', async client => {
16+
const [, reply] = await Promise.all([
17+
client.mSet({
18+
'1': 'abc',
19+
'2': 'bc'
20+
}),
21+
client.lcsIdx('1', '2')
22+
]);
2323

24-
assert.deepEqual(
25-
reply,
26-
{
27-
matches: [{
28-
key1: {
29-
start: 1,
30-
end: 2
31-
},
32-
key2: {
33-
start: 0,
34-
end: 1
35-
}
36-
}],
37-
length: 2
38-
}
39-
);
40-
}, GLOBAL.SERVERS.OPEN);
24+
console.log(reply);
25+
26+
assert.deepEqual(
27+
reply,
28+
{
29+
matches: [[[1, 2], [0, 1]]],
30+
len: 2
31+
}
32+
);
33+
}, GLOBAL.SERVERS.OPEN);
4134
});
Lines changed: 50 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,50 @@
1-
// import { RedisArgument, TuplesToMapReply, BlobStringReply, ArrayReply, NumberReply, Resp2Reply, Command, TuplesReply } from '../RESP/types';
2-
// import LCS from './LCS';
3-
4-
// export interface LcsIdxOptions {
5-
// MINMATCHLEN?: number;
6-
// }
7-
8-
// export type LcsIdxRange = TuplesReply<[
9-
// start: NumberReply,
10-
// end: NumberReply
11-
// ]>;
12-
13-
// export type LcsIdxMatches = ArrayReply<
14-
// TuplesReply<[
15-
// key1: LcsIdxRange,
16-
// key2: LcsIdxRange
17-
// ]>
18-
// >;
19-
20-
// export type LcsIdxReply = TuplesToMapReply<[
21-
// [BlobStringReply<'matches'>, LcsIdxMatches],
22-
// [BlobStringReply<'len'>, NumberReply]
23-
// ]>;
24-
25-
// export default {
26-
// FIRST_KEY_INDEX: LCS.FIRST_KEY_INDEX,
27-
// IS_READ_ONLY: LCS.IS_READ_ONLY,
28-
// transformArguments(
29-
// key1: RedisArgument,
30-
// key2: RedisArgument,
31-
// options?: LcsIdxOptions
32-
// ) {
33-
// const args = LCS.transformArguments(key1, key2);
34-
35-
// if (options?.MINMATCHLEN) {
36-
// args.push('MINMATCHLEN', options.MINMATCHLEN.toString());
37-
// }
38-
39-
// return args;
40-
// },
41-
// transformReply: {
42-
// 2: (reply: Resp2Reply<LcsIdxReply>) => ({
43-
// matches: reply[1],
44-
// len: reply[2]
45-
// }),
46-
// 3: undefined as unknown as () => LcsIdxReply
47-
// }
48-
// } as const satisfies Command;
1+
import { RedisArgument, TuplesToMapReply, BlobStringReply, ArrayReply, NumberReply, Resp2Reply, Command, TuplesReply } from '../RESP/types';
2+
import LCS from './LCS';
3+
4+
export interface LcsIdxOptions {
5+
MINMATCHLEN?: number;
6+
}
7+
8+
export type LcsIdxRange = TuplesReply<[
9+
start: NumberReply,
10+
end: NumberReply
11+
]>;
12+
13+
export type LcsIdxMatches = ArrayReply<
14+
TuplesReply<[
15+
key1: LcsIdxRange,
16+
key2: LcsIdxRange
17+
]>
18+
>;
19+
20+
export type LcsIdxReply = TuplesToMapReply<[
21+
[BlobStringReply<'matches'>, LcsIdxMatches],
22+
[BlobStringReply<'len'>, NumberReply]
23+
]>;
24+
25+
export default {
26+
FIRST_KEY_INDEX: LCS.FIRST_KEY_INDEX,
27+
IS_READ_ONLY: LCS.IS_READ_ONLY,
28+
transformArguments(
29+
key1: RedisArgument,
30+
key2: RedisArgument,
31+
options?: LcsIdxOptions
32+
) {
33+
const args = LCS.transformArguments(key1, key2);
34+
35+
args.push('IDX');
36+
37+
if (options?.MINMATCHLEN) {
38+
args.push('MINMATCHLEN', options.MINMATCHLEN.toString());
39+
}
40+
41+
return args;
42+
},
43+
transformReply: {
44+
2: (reply: Resp2Reply<LcsIdxReply>) => ({
45+
matches: reply[1],
46+
len: reply[3]
47+
}),
48+
3: undefined as unknown as () => LcsIdxReply
49+
}
50+
} as const satisfies Command;
Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,35 @@
11
import { strict as assert } from 'assert';
22
import testUtils, { GLOBAL } from '../test-utils';
3-
import { transformArguments } from './LCS_IDX_WITHMATCHLEN';
3+
import LCS_IDX_WITHMATCHLEN from './LCS_IDX_WITHMATCHLEN';
44

5-
describe('LCS_IDX_WITHMATCHLEN', () => {
6-
testUtils.isVersionGreaterThanHook([7]);
5+
describe('LCS IDX WITHMATCHLEN', () => {
6+
testUtils.isVersionGreaterThanHook([7]);
77

8-
it('transformArguments', () => {
9-
assert.deepEqual(
10-
transformArguments('1', '2'),
11-
['LCS', '1', '2', 'IDX', 'WITHMATCHLEN']
12-
);
13-
});
8+
it('transformArguments', () => {
9+
assert.deepEqual(
10+
LCS_IDX_WITHMATCHLEN.transformArguments('1', '2'),
11+
['LCS', '1', '2', 'IDX', 'WITHMATCHLEN']
12+
);
13+
});
1414

15-
testUtils.testWithClient('client.lcsIdxWithMatchLen', async client => {
16-
const [, reply] = await Promise.all([
17-
client.mSet({
18-
'1': 'abc',
19-
'2': 'bc'
20-
}),
21-
client.lcsIdxWithMatchLen('1', '2')
22-
]);
15+
testUtils.testWithClient('client.lcsIdxWithMatchLen', async client => {
16+
const [, reply] = await Promise.all([
17+
client.mSet({
18+
'1': 'abc',
19+
'2': 'bc'
20+
}),
21+
client.lcsIdxWithMatchLen('1', '2')
22+
]);
2323

24-
assert.deepEqual(
25-
reply,
26-
{
27-
matches: [{
28-
key1: {
29-
start: 1,
30-
end: 2
31-
},
32-
key2: {
33-
start: 0,
34-
end: 1
35-
},
36-
length: 2
37-
}],
38-
length: 2
39-
}
40-
);
41-
}, GLOBAL.SERVERS.OPEN);
24+
assert.deepEqual(
25+
reply,
26+
{
27+
matches: [
28+
[[[1, 2], [0, 1]]],
29+
2
30+
],
31+
len: 2
32+
}
33+
);
34+
}, GLOBAL.SERVERS.OPEN);
4235
});
Lines changed: 33 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,36 @@
1-
// import { RedisArgument, TuplesToMapReply, BlobStringReply, ArrayReply, NumberReply, Resp2Reply, Command, TuplesReply } from '../RESP/types';
2-
// import LCS from './LCS';
3-
// import { LcsIdxRange } from './LCS_IDX';
1+
import { RedisArgument, TuplesToMapReply, BlobStringReply, ArrayReply, NumberReply, Resp2Reply, Command, TuplesReply } from '../RESP/types';
2+
import LCS_IDX, { LcsIdxOptions, LcsIdxRange } from './LCS_IDX';
43

5-
// interface LcsIdxOptions {
6-
// MINMATCHLEN?: number;
7-
// }
4+
export type LcsIdxWithMatchLenMatches = ArrayReply<
5+
TuplesReply<[
6+
key1: LcsIdxRange,
7+
key2: LcsIdxRange,
8+
len: NumberReply
9+
]>
10+
>;
811

9-
// export type LcsIdxWithMatchLenMatches = ArrayReply<
10-
// TuplesReply<[
11-
// key1: LcsIdxRange,
12-
// key2: LcsIdxRange,
13-
// len: NumberReply
14-
// ]>
15-
// >;
12+
export type LcsIdxWithMatchLenReply = TuplesToMapReply<[
13+
[BlobStringReply<'matches'>, LcsIdxWithMatchLenMatches],
14+
[BlobStringReply<'len'>, NumberReply]
15+
]>;
1616

17-
// export type LcsIdxReply = TuplesToMapReply<[
18-
// [BlobStringReply<'matches'>, LcsIdxWithMatchLenMatches],
19-
// [BlobStringReply<'len'>, NumberReply]
20-
// ]>;
21-
22-
// export default {
23-
// FIRST_KEY_INDEX: LCS.FIRST_KEY_INDEX,
24-
// IS_READ_ONLY: LCS.IS_READ_ONLY,
25-
// transformArguments(
26-
// key1: RedisArgument,
27-
// key2: RedisArgument,
28-
// options?: LcsIdxOptions
29-
// ) {
30-
// const args = LCS.transformArguments(key1, key2);
31-
32-
// if (options?.MINMATCHLEN) {
33-
// args.push('MINMATCHLEN', options.MINMATCHLEN.toString());
34-
// }
35-
36-
// args.push('WITHMATCHLEN');
37-
38-
// return args;
39-
// },
40-
// transformReply: {
41-
// 2: (reply: Resp2Reply<LcsIdxReply>) => ({
42-
// matches: reply[1],
43-
// len: reply[2]
44-
// }),
45-
// 3: undefined as unknown as () => LcsIdxReply
46-
// }
47-
// } as const satisfies Command;
17+
export default {
18+
FIRST_KEY_INDEX: LCS_IDX.FIRST_KEY_INDEX,
19+
IS_READ_ONLY: LCS_IDX.IS_READ_ONLY,
20+
transformArguments(
21+
key1: RedisArgument,
22+
key2: RedisArgument,
23+
options?: LcsIdxOptions
24+
) {
25+
const args = LCS_IDX.transformArguments(key1, key2);
26+
args.push('WITHMATCHLEN');
27+
return args;
28+
},
29+
transformReply: {
30+
2: (reply: Resp2Reply<LcsIdxWithMatchLenReply>) => ({
31+
matches: reply[1],
32+
len: reply[3]
33+
}),
34+
3: undefined as unknown as () => LcsIdxWithMatchLenReply
35+
}
36+
} as const satisfies Command;
Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
import { strict as assert } from 'assert';
22
import testUtils, { GLOBAL } from '../test-utils';
3-
import { transformArguments } from './LOLWUT';
3+
import LOLWUT from './LOLWUT';
44

55
describe('LOLWUT', () => {
6-
describe('transformArguments', () => {
7-
it('simple', () => {
8-
assert.deepEqual(
9-
transformArguments(),
10-
['LOLWUT']
11-
);
12-
});
6+
describe('transformArguments', () => {
7+
it('simple', () => {
8+
assert.deepEqual(
9+
LOLWUT.transformArguments(),
10+
['LOLWUT']
11+
);
12+
});
1313

14-
it('with version', () => {
15-
assert.deepEqual(
16-
transformArguments(5),
17-
['LOLWUT', 'VERSION', '5']
18-
);
19-
});
14+
it('with version', () => {
15+
assert.deepEqual(
16+
LOLWUT.transformArguments(5),
17+
['LOLWUT', 'VERSION', '5']
18+
);
19+
});
2020

21-
it('with version and optional arguments', () => {
22-
assert.deepEqual(
23-
transformArguments(5, 1, 2, 3),
24-
['LOLWUT', 'VERSION', '5', '1', '2', '3']
25-
);
26-
});
21+
it('with version and optional arguments', () => {
22+
assert.deepEqual(
23+
LOLWUT.transformArguments(5, 1, 2, 3),
24+
['LOLWUT', 'VERSION', '5', '1', '2', '3']
25+
);
2726
});
27+
});
2828

29-
testUtils.testWithClient('client.LOLWUT', async client => {
30-
assert.equal(
31-
typeof (await client.LOLWUT()),
32-
'string'
33-
);
34-
}, GLOBAL.SERVERS.OPEN);
29+
testUtils.testWithClient('client.LOLWUT', async client => {
30+
assert.equal(
31+
typeof (await client.LOLWUT()),
32+
'string'
33+
);
34+
}, GLOBAL.SERVERS.OPEN);
3535
});

0 commit comments

Comments
 (0)