Skip to content

Commit 5576a0d

Browse files
authored
CAE-193: add "IGNORE" options to time series commands (for v4 branch) (#2752)
1 parent a1bee1c commit 5576a0d

File tree

7 files changed

+65
-11
lines changed

7 files changed

+65
-11
lines changed

packages/time-series/lib/commands/ADD.spec.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,26 @@ describe('ADD', () => {
5757
);
5858
});
5959

60-
it('with RETENTION, ENCODING, CHUNK_SIZE, ON_DUPLICATE, LABELS', () => {
60+
it('with IGNORE', () => {
61+
assert.deepEqual(
62+
transformArguments('key', '*', 1, {
63+
IGNORE: { MAX_TIME_DIFF: 1, MAX_VAL_DIFF: 1}
64+
}),
65+
['TS.ADD', 'key', '*', '1', 'IGNORE', '1', '1']
66+
)
67+
});
68+
69+
it('with RETENTION, ENCODING, CHUNK_SIZE, ON_DUPLICATE, LABELS, IGNORE', () => {
6170
assert.deepEqual(
6271
transformArguments('key', '*', 1, {
6372
RETENTION: 1,
6473
ENCODING: TimeSeriesEncoding.UNCOMPRESSED,
6574
CHUNK_SIZE: 1,
6675
ON_DUPLICATE: TimeSeriesDuplicatePolicies.BLOCK,
67-
LABELS: { label: 'value' }
76+
LABELS: { label: 'value' },
77+
IGNORE: { MAX_TIME_DIFF: 1, MAX_VAL_DIFF: 1}
6878
}),
69-
['TS.ADD', 'key', '*', '1', 'RETENTION', '1', 'ENCODING', 'UNCOMPRESSED', 'CHUNK_SIZE', '1', 'ON_DUPLICATE', 'BLOCK', 'LABELS', 'label', 'value']
79+
['TS.ADD', 'key', '*', '1', 'RETENTION', '1', 'ENCODING', 'UNCOMPRESSED', 'CHUNK_SIZE', '1', 'ON_DUPLICATE', 'BLOCK', 'LABELS', 'label', 'value', 'IGNORE', '1', '1']
7080
);
7181
});
7282
});

packages/time-series/lib/commands/ADD.ts

+9
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,21 @@ import {
88
Labels,
99
pushLabelsArgument,
1010
Timestamp,
11+
pushIgnoreArgument,
1112
} from '.';
1213

14+
export interface TsIgnoreOptions {
15+
MAX_TIME_DIFF: number;
16+
MAX_VAL_DIFF: number;
17+
}
18+
1319
interface AddOptions {
1420
RETENTION?: number;
1521
ENCODING?: TimeSeriesEncoding;
1622
CHUNK_SIZE?: number;
1723
ON_DUPLICATE?: TimeSeriesDuplicatePolicies;
1824
LABELS?: Labels;
25+
IGNORE?: TsIgnoreOptions;
1926
}
2027

2128
export const FIRST_KEY_INDEX = 1;
@@ -40,6 +47,8 @@ export function transformArguments(key: string, timestamp: Timestamp, value: num
4047

4148
pushLabelsArgument(args, options?.LABELS);
4249

50+
pushIgnoreArgument(args, options?.IGNORE);
51+
4352
return args;
4453
}
4554

packages/time-series/lib/commands/ALTER.spec.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,25 @@ describe('ALTER', () => {
4848
);
4949
});
5050

51-
it('with RETENTION, CHUNK_SIZE, DUPLICATE_POLICY, LABELS', () => {
51+
it('with IGNORE with MAX_TIME_DIFF', () => {
52+
assert.deepEqual(
53+
transformArguments('key', {
54+
IGNORE: { MAX_TIME_DIFF: 1, MAX_VAL_DIFF: 1}
55+
}),
56+
['TS.ALTER', 'key', 'IGNORE', '1', '1']
57+
)
58+
});
59+
60+
it('with RETENTION, CHUNK_SIZE, DUPLICATE_POLICY, LABELS, IGNORE', () => {
5261
assert.deepEqual(
5362
transformArguments('key', {
5463
RETENTION: 1,
5564
CHUNK_SIZE: 1,
5665
DUPLICATE_POLICY: TimeSeriesDuplicatePolicies.BLOCK,
57-
LABELS: { label: 'value' }
66+
LABELS: { label: 'value' },
67+
IGNORE: { MAX_TIME_DIFF: 1, MAX_VAL_DIFF: 1}
5868
}),
59-
['TS.ALTER', 'key', 'RETENTION', '1', 'CHUNK_SIZE', '1', 'DUPLICATE_POLICY', 'BLOCK', 'LABELS', 'label', 'value']
69+
['TS.ALTER', 'key', 'RETENTION', '1', 'CHUNK_SIZE', '1', 'DUPLICATE_POLICY', 'BLOCK', 'LABELS', 'label', 'value', 'IGNORE', '1', '1']
6070
);
6171
});
6272
});

packages/time-series/lib/commands/ALTER.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { pushRetentionArgument, Labels, pushLabelsArgument, TimeSeriesDuplicatePolicies, pushChunkSizeArgument, pushDuplicatePolicy } from '.';
1+
import { pushRetentionArgument, Labels, pushLabelsArgument, TimeSeriesDuplicatePolicies, pushChunkSizeArgument, pushDuplicatePolicy, pushIgnoreArgument } from '.';
2+
import { TsIgnoreOptions } from './ADD';
23

34
export const FIRST_KEY_INDEX = 1;
45

@@ -7,6 +8,7 @@ interface AlterOptions {
78
CHUNK_SIZE?: number;
89
DUPLICATE_POLICY?: TimeSeriesDuplicatePolicies;
910
LABELS?: Labels;
11+
IGNORE?: TsIgnoreOptions;
1012
}
1113

1214
export function transformArguments(key: string, options?: AlterOptions): Array<string> {
@@ -20,6 +22,8 @@ export function transformArguments(key: string, options?: AlterOptions): Array<s
2022

2123
pushLabelsArgument(args, options?.LABELS);
2224

25+
pushIgnoreArgument(args, options?.IGNORE);
26+
2327
return args;
2428
}
2529

packages/time-series/lib/commands/CREATE.spec.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,27 @@ describe('CREATE', () => {
5656
['TS.CREATE', 'key', 'LABELS', 'label', 'value']
5757
);
5858
});
59+
60+
it('with IGNORE with MAX_TIME_DIFF', () => {
61+
assert.deepEqual(
62+
transformArguments('key', {
63+
IGNORE: { MAX_TIME_DIFF: 1, MAX_VAL_DIFF: 1}
64+
}),
65+
['TS.CREATE', 'key', 'IGNORE', '1', '1']
66+
)
67+
});
5968

60-
it('with RETENTION, ENCODING, CHUNK_SIZE, DUPLICATE_POLICY, LABELS', () => {
69+
it('with RETENTION, ENCODING, CHUNK_SIZE, DUPLICATE_POLICY, LABELS, IGNORE', () => {
6170
assert.deepEqual(
6271
transformArguments('key', {
6372
RETENTION: 1,
6473
ENCODING: TimeSeriesEncoding.UNCOMPRESSED,
6574
CHUNK_SIZE: 1,
6675
DUPLICATE_POLICY: TimeSeriesDuplicatePolicies.BLOCK,
67-
LABELS: { label: 'value' }
76+
LABELS: { label: 'value' },
77+
IGNORE: { MAX_TIME_DIFF: 1, MAX_VAL_DIFF: 1}
6878
}),
69-
['TS.CREATE', 'key', 'RETENTION', '1', 'ENCODING', 'UNCOMPRESSED', 'CHUNK_SIZE', '1', 'DUPLICATE_POLICY', 'BLOCK', 'LABELS', 'label', 'value']
79+
['TS.CREATE', 'key', 'RETENTION', '1', 'ENCODING', 'UNCOMPRESSED', 'CHUNK_SIZE', '1', 'DUPLICATE_POLICY', 'BLOCK', 'LABELS', 'label', 'value', 'IGNORE', '1', '1']
7080
);
7181
});
7282
});

packages/time-series/lib/commands/CREATE.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import {
66
TimeSeriesDuplicatePolicies,
77
Labels,
88
pushLabelsArgument,
9-
pushDuplicatePolicy
9+
pushDuplicatePolicy,
10+
pushIgnoreArgument
1011
} from '.';
12+
import { TsIgnoreOptions } from './ADD';
1113

1214
export const FIRST_KEY_INDEX = 1;
1315

@@ -17,6 +19,7 @@ interface CreateOptions {
1719
CHUNK_SIZE?: number;
1820
DUPLICATE_POLICY?: TimeSeriesDuplicatePolicies;
1921
LABELS?: Labels;
22+
IGNORE?: TsIgnoreOptions;
2023
}
2124

2225
export function transformArguments(key: string, options?: CreateOptions): Array<string> {
@@ -32,6 +35,8 @@ export function transformArguments(key: string, options?: CreateOptions): Array<
3235

3336
pushLabelsArgument(args, options?.LABELS);
3437

38+
pushIgnoreArgument(args, options?.IGNORE);
39+
3540
return args;
3641
}
3742

packages/time-series/lib/commands/index.ts

+6
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ export function transformTimestampArgument(timestamp: Timestamp): string {
127127
).toString();
128128
}
129129

130+
export function pushIgnoreArgument(args: RedisCommandArguments, ignore?: ADD.TsIgnoreOptions) {
131+
if (ignore !== undefined) {
132+
args.push('IGNORE', ignore.MAX_TIME_DIFF.toString(), ignore.MAX_VAL_DIFF.toString());
133+
}
134+
}
135+
130136
export function pushRetentionArgument(args: RedisCommandArguments, retention?: number): RedisCommandArguments {
131137
if (retention !== undefined) {
132138
args.push(

0 commit comments

Comments
 (0)