Skip to content

Commit 8c1c28d

Browse files
committed
close #2216 - add support for TDIGEST.MERGESTORE and make compression optional on TDIGEST.CREATE
1 parent 6b15f03 commit 8c1c28d

File tree

6 files changed

+103
-13
lines changed

6 files changed

+103
-13
lines changed

packages/bloom/lib/commands/t-digest/CREATE.spec.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,20 @@ import testUtils, { GLOBAL } from '../../test-utils';
33
import { transformArguments } from './CREATE';
44

55
describe('TDIGEST.CREATE', () => {
6-
it('transformArguments', () => {
7-
assert.deepEqual(
8-
transformArguments('key', 100),
9-
['TDIGEST.CREATE', 'key', '100']
10-
);
6+
describe('transformArguments', () => {
7+
it('without options', () => {
8+
assert.deepEqual(
9+
transformArguments('key'),
10+
['TDIGEST.CREATE', 'key']
11+
);
12+
});
13+
14+
it('without compression', () => {
15+
assert.deepEqual(
16+
transformArguments('key', 100),
17+
['TDIGEST.CREATE', 'key', '100']
18+
);
19+
});
1120
});
1221

1322
testUtils.testWithClient('client.tDigest.create', async client => {

packages/bloom/lib/commands/t-digest/CREATE.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,23 @@ export const FIRST_KEY_INDEX = 1;
44

55
export function transformArguments(
66
key: RedisCommandArgument,
7-
compression: number
7+
it('simple', () => {
8+
assert.deepEqual(
9+
transformArguments('key', 100),
10+
['TDIGEST.CREATE', 'key', '100']
11+
);
12+
});?: number
813
): RedisCommandArguments {
9-
return [
14+
const args = [
1015
'TDIGEST.CREATE',
11-
key,
12-
compression.toString()
16+
key
1317
];
18+
19+
if (compression) {
20+
args.push(compression.toString());
21+
}
22+
23+
return args;
1424
}
1525

1626
export declare function transformReply(): 'OK';

packages/bloom/lib/commands/t-digest/MERGE.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import { RedisCommandArgument, RedisCommandArguments } from '@redis/client/dist/
33
export const FIRST_KEY_INDEX = 1;
44

55
export function transformArguments(
6-
toKey: RedisCommandArgument,
7-
fromKey: RedisCommandArgument
6+
destKey: RedisCommandArgument,
7+
srcKey: RedisCommandArgument
88
): RedisCommandArguments {
99
return [
1010
'TS.MERGE',
11-
toKey,
12-
fromKey
11+
destKey,
12+
srcKey
1313
];
1414
}
1515

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { strict as assert } from 'assert';
2+
import testUtils, { GLOBAL } from '../../test-utils';
3+
import { transformArguments } from './MERGESTORE';
4+
5+
describe('TDIGEST.MERGESTORE', () => {
6+
describe('transformArguments', () => {
7+
describe('srcKeys', () => {
8+
it('string', () => {
9+
assert.deepEqual(
10+
transformArguments('dest', ['1', '2']),
11+
['TDIGEST.MERGESTORE', 'dest', '1', '1', '2']
12+
);
13+
});
14+
15+
it('Array', () => {
16+
assert.deepEqual(
17+
transformArguments('dest', 'src'),
18+
['TDIGEST.MERGESTORE', 'dest', '1', 'src']
19+
);
20+
});
21+
});
22+
23+
it('with COMPRESSION', () => {
24+
assert.deepEqual(
25+
transformArguments('dest', 'src', {
26+
COMPRESSION: 100
27+
}),
28+
['TDIGEST.MERGESTORE', 'dest', '1', 'src', 'COMPRESSION', '100']
29+
);
30+
});
31+
});
32+
33+
testUtils.testWithClient('client.tDigest.mergeStore', async client => {
34+
assert.equal(
35+
await client.tDigest.mergeStore('dest', 'src'),
36+
'OK'
37+
);
38+
}, GLOBAL.SERVERS.OPEN);
39+
});
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { RedisCommandArgument, RedisCommandArguments } from '@redis/client/dist/lib/commands';
2+
import { pushVerdictArgument } from '@redis/client/dist/lib/commands/generic-transformers';
3+
4+
export const FIRST_KEY_INDEX = 1;
5+
6+
interface MergeStoreOptions {
7+
COMPRESSION?: number;
8+
}
9+
10+
export function transformArguments(
11+
destKey: RedisCommandArgument,
12+
srcKeys: RedisCommandArgument | Array<RedisCommandArgument>,
13+
options?: MergeStoreOptions
14+
): RedisCommandArguments {
15+
let args = [
16+
'TS.MERGESTORE',
17+
destKey,
18+
];
19+
20+
args = pushVerdictArgument(args, srcKeys);
21+
22+
if (options?.COMPRESSION) {
23+
args.push('COMPRESSION', options.COMPRESSION.toString());
24+
}
25+
26+
return args;
27+
}
28+
29+
export declare function transformReply(): 'OK';

packages/bloom/lib/commands/t-digest/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as CREATE from './CREATE';
44
import * as INFO from './INFO';
55
import * as MAX from './MAX';
66
import * as MERGE from './MERGE';
7+
import * as MERGESTORE from './MERGESTORE';
78
import * as MIN from './MIN';
89
import * as QUANTILE from './QUANTILE';
910
import * as RESET from './RESET';
@@ -22,6 +23,8 @@ export default {
2223
max: MAX,
2324
MERGE,
2425
merge: MERGE,
26+
MERGESTORE,
27+
mergeStore: MERGESTORE,
2528
MIN,
2629
min: MIN,
2730
QUANTILE,

0 commit comments

Comments
 (0)