Skip to content

Commit f7d824c

Browse files
authored
CAE-193: add "IGNORE" options to time series commands (for v5 branch) (#2753)
* CAE-193: add "IGNORE" options to time series commands (for v5 branch) * add INCR/DECR and modify tests to not test ignore on older version * require maxTimeDiff/maxValDiff to be specified also rename them * fix add/ignore test after api change * update tests for api change in IGNORE option
1 parent 949b944 commit f7d824c

File tree

10 files changed

+110
-19
lines changed

10 files changed

+110
-19
lines changed

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,29 @@ describe('TS.ADD', () => {
5757
);
5858
});
5959

60-
it('with RETENTION, ENCODING, CHUNK_SIZE, ON_DUPLICATE, LABELS', () => {
60+
it ('with IGNORE', () => {
61+
assert.deepEqual(
62+
ADD.transformArguments('key', '*', 1, {
63+
IGNORE: {
64+
maxTimeDiff: 1,
65+
maxValDiff: 1
66+
}
67+
}),
68+
['TS.ADD', 'key', '*', '1', 'IGNORE', '1', '1']
69+
)
70+
});
71+
72+
it('with RETENTION, ENCODING, CHUNK_SIZE, ON_DUPLICATE, LABELS, IGNORE', () => {
6173
assert.deepEqual(
6274
ADD.transformArguments('key', '*', 1, {
6375
RETENTION: 1,
6476
ENCODING: TIME_SERIES_ENCODING.UNCOMPRESSED,
6577
CHUNK_SIZE: 1,
6678
ON_DUPLICATE: TIME_SERIES_DUPLICATE_POLICIES.BLOCK,
67-
LABELS: { label: 'value' }
79+
LABELS: { label: 'value' },
80+
IGNORE: { maxTimeDiff: 1, maxValDiff: 1}
6881
}),
69-
['TS.ADD', 'key', '*', '1', 'RETENTION', '1', 'ENCODING', 'UNCOMPRESSED', 'CHUNK_SIZE', '1', 'ON_DUPLICATE', 'BLOCK', 'LABELS', 'label', 'value']
82+
['TS.ADD', 'key', '*', '1', 'RETENTION', '1', 'ENCODING', 'UNCOMPRESSED', 'CHUNK_SIZE', '1', 'ON_DUPLICATE', 'BLOCK', 'LABELS', 'label', 'value', 'IGNORE', '1', '1']
7083
);
7184
});
7285
});

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,22 @@ import {
88
TimeSeriesDuplicatePolicies,
99
Labels,
1010
pushLabelsArgument,
11-
Timestamp
11+
Timestamp,
12+
pushIgnoreArgument
1213
} from '.';
1314

15+
export interface TsIgnoreOptions {
16+
maxTimeDiff: number;
17+
maxValDiff: number;
18+
}
19+
1420
export interface TsAddOptions {
1521
RETENTION?: number;
1622
ENCODING?: TimeSeriesEncoding;
1723
CHUNK_SIZE?: number;
1824
ON_DUPLICATE?: TimeSeriesDuplicatePolicies;
1925
LABELS?: Labels;
26+
IGNORE?: TsIgnoreOptions;
2027
}
2128

2229
export default {
@@ -47,6 +54,8 @@ export default {
4754

4855
pushLabelsArgument(args, options?.LABELS);
4956

57+
pushIgnoreArgument(args, options?.IGNORE);
58+
5059
return args;
5160
},
5261
transformReply: undefined as unknown as () => NumberReply

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,28 @@ describe('TS.ALTER', () => {
4848
);
4949
});
5050

51-
it('with RETENTION, CHUNK_SIZE, DUPLICATE_POLICY, LABELS', () => {
51+
it('with IGNORE', () => {
52+
assert.deepEqual(
53+
ALTER.transformArguments('key', {
54+
IGNORE: {
55+
maxTimeDiff: 1,
56+
maxValDiff: 1
57+
}
58+
}),
59+
['TS.ALTER', 'key', 'IGNORE', '1', '1']
60+
)
61+
});
62+
63+
it('with RETENTION, CHUNK_SIZE, DUPLICATE_POLICY, LABELS, IGNORE', () => {
5264
assert.deepEqual(
5365
ALTER.transformArguments('key', {
5466
RETENTION: 1,
5567
CHUNK_SIZE: 1,
5668
DUPLICATE_POLICY: TIME_SERIES_DUPLICATE_POLICIES.BLOCK,
57-
LABELS: { label: 'value' }
69+
LABELS: { label: 'value' },
70+
IGNORE: { maxTimeDiff: 1, maxValDiff: 1}
5871
}),
59-
['TS.ALTER', 'key', 'RETENTION', '1', 'CHUNK_SIZE', '1', 'DUPLICATE_POLICY', 'BLOCK', 'LABELS', 'label', 'value']
72+
['TS.ALTER', 'key', 'RETENTION', '1', 'CHUNK_SIZE', '1', 'DUPLICATE_POLICY', 'BLOCK', 'LABELS', 'label', 'value', 'IGNORE', '1', '1']
6073
);
6174
});
6275
});

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { RedisArgument, SimpleStringReply, Command } from '@redis/client/dist/lib/RESP/types';
22
import { TsCreateOptions } from './CREATE';
3-
import { pushRetentionArgument, pushChunkSizeArgument, pushDuplicatePolicy, pushLabelsArgument } from '.';
3+
import { pushRetentionArgument, pushChunkSizeArgument, pushDuplicatePolicy, pushLabelsArgument, pushIgnoreArgument } from '.';
44

5-
export type TsAlterOptions = Pick<TsCreateOptions, 'RETENTION' | 'CHUNK_SIZE' | 'DUPLICATE_POLICY' | 'LABELS'>;
5+
export type TsAlterOptions = Pick<TsCreateOptions, 'RETENTION' | 'CHUNK_SIZE' | 'DUPLICATE_POLICY' | 'LABELS' | 'IGNORE'>;
66

77
export default {
88
FIRST_KEY_INDEX: 1,
@@ -18,6 +18,8 @@ export default {
1818

1919
pushLabelsArgument(args, options?.LABELS);
2020

21+
pushIgnoreArgument(args, options?.IGNORE);
22+
2123
return args;
2224
},
2325
transformReply: undefined as unknown as () => SimpleStringReply<'OK'>

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,29 @@ describe('TS.CREATE', () => {
5757
);
5858
});
5959

60-
it('with RETENTION, ENCODING, CHUNK_SIZE, DUPLICATE_POLICY, LABELS', () => {
60+
it('with IGNORE', () => {
61+
assert.deepEqual(
62+
CREATE.transformArguments('key', {
63+
IGNORE: {
64+
maxTimeDiff: 1,
65+
maxValDiff: 1
66+
}
67+
}),
68+
['TS.CREATE', 'key', 'IGNORE', '1', '1']
69+
)
70+
});
71+
72+
it('with RETENTION, ENCODING, CHUNK_SIZE, DUPLICATE_POLICY, LABELS, IGNORE', () => {
6173
assert.deepEqual(
6274
CREATE.transformArguments('key', {
6375
RETENTION: 1,
6476
ENCODING: TIME_SERIES_ENCODING.UNCOMPRESSED,
6577
CHUNK_SIZE: 1,
6678
DUPLICATE_POLICY: TIME_SERIES_DUPLICATE_POLICIES.BLOCK,
67-
LABELS: { label: 'value' }
79+
LABELS: { label: 'value' },
80+
IGNORE: { maxTimeDiff: 1, maxValDiff: 1}
6881
}),
69-
['TS.CREATE', 'key', 'RETENTION', '1', 'ENCODING', 'UNCOMPRESSED', 'CHUNK_SIZE', '1', 'DUPLICATE_POLICY', 'BLOCK', 'LABELS', 'label', 'value']
82+
['TS.CREATE', 'key', 'RETENTION', '1', 'ENCODING', 'UNCOMPRESSED', 'CHUNK_SIZE', '1', 'DUPLICATE_POLICY', 'BLOCK', 'LABELS', 'label', 'value', 'IGNORE', '1', '1']
7083
);
7184
});
7285
});

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,18 @@ import {
77
TimeSeriesDuplicatePolicies,
88
pushDuplicatePolicy,
99
Labels,
10-
pushLabelsArgument
10+
pushLabelsArgument,
11+
pushIgnoreArgument
1112
} from '.';
13+
import { TsIgnoreOptions } from './ADD';
1214

1315
export interface TsCreateOptions {
1416
RETENTION?: number;
1517
ENCODING?: TimeSeriesEncoding;
1618
CHUNK_SIZE?: number;
1719
DUPLICATE_POLICY?: TimeSeriesDuplicatePolicies;
1820
LABELS?: Labels;
21+
IGNORE?: TsIgnoreOptions;
1922
}
2023

2124
export default {
@@ -34,6 +37,8 @@ export default {
3437

3538
pushLabelsArgument(args, options?.LABELS);
3639

40+
pushIgnoreArgument(args, options?.IGNORE);
41+
3742
return args;
3843
},
3944
transformReply: undefined as unknown as () => SimpleStringReply<'OK'>

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,29 @@ describe('TS.DECRBY', () => {
5656
);
5757
});
5858

59+
it ('with IGNORE', () => {
60+
assert.deepEqual(
61+
DECRBY.transformArguments('key', 1, {
62+
IGNORE: {
63+
maxTimeDiff: 1,
64+
maxValDiff: 1
65+
}
66+
}),
67+
['TS.DECRBY', 'key', '1', 'IGNORE', '1', '1']
68+
)
69+
});
70+
5971
it('with TIMESTAMP, RETENTION, UNCOMPRESSED, CHUNK_SIZE and LABELS', () => {
6072
assert.deepEqual(
6173
DECRBY.transformArguments('key', 1, {
6274
TIMESTAMP: '*',
6375
RETENTION: 1,
6476
UNCOMPRESSED: true,
6577
CHUNK_SIZE: 2,
66-
LABELS: { label: 'value' }
78+
LABELS: { label: 'value' },
79+
IGNORE: { maxTimeDiff: 1, maxValDiff: 1 }
6780
}),
68-
['TS.DECRBY', 'key', '1', 'TIMESTAMP', '*', 'RETENTION', '1', 'UNCOMPRESSED', 'CHUNK_SIZE', '2', 'LABELS', 'label', 'value']
81+
['TS.DECRBY', 'key', '1', 'TIMESTAMP', '*', 'RETENTION', '1', 'UNCOMPRESSED', 'CHUNK_SIZE', '2', 'LABELS', 'label', 'value', 'IGNORE', '1', '1']
6982
);
7083
});
7184
});

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,30 @@ describe('TS.INCRBY', () => {
6565
);
6666
});
6767

68+
it ('with IGNORE', () => {
69+
assert.deepEqual(
70+
INCRBY.transformArguments('key', 1, {
71+
IGNORE: {
72+
maxTimeDiff: 1,
73+
maxValDiff: 1
74+
}
75+
}),
76+
['TS.INCRBY', 'key', '1', 'IGNORE', '1', '1']
77+
)
78+
});
79+
6880
it('with TIMESTAMP, RETENTION, UNCOMPRESSED, CHUNK_SIZE and LABELS', () => {
6981
assert.deepEqual(
7082
INCRBY.transformArguments('key', 1, {
7183
TIMESTAMP: '*',
7284
RETENTION: 1,
7385
UNCOMPRESSED: true,
7486
CHUNK_SIZE: 1,
75-
LABELS: { label: 'value' }
87+
LABELS: { label: 'value' },
88+
IGNORE: { maxTimeDiff: 1, maxValDiff: 1 }
7689
}),
7790
['TS.INCRBY', 'key', '1', 'TIMESTAMP', '*', 'RETENTION', '1', 'UNCOMPRESSED',
78-
'CHUNK_SIZE', '1', 'LABELS', 'label', 'value']
91+
'CHUNK_SIZE', '1', 'LABELS', 'label', 'value', 'IGNORE', '1', '1']
7992
);
8093
});
8194
});

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { RedisArgument, NumberReply, Command } from '@redis/client/dist/lib/RESP/types';
2-
import { Timestamp, transformTimestampArgument, pushRetentionArgument, pushChunkSizeArgument, Labels, pushLabelsArgument } from '.';
2+
import { Timestamp, transformTimestampArgument, pushRetentionArgument, pushChunkSizeArgument, Labels, pushLabelsArgument, pushIgnoreArgument } from '.';
3+
import { TsIgnoreOptions } from './ADD';
34

45
export interface TsIncrByOptions {
56
TIMESTAMP?: Timestamp;
67
RETENTION?: number;
78
UNCOMPRESSED?: boolean;
89
CHUNK_SIZE?: number;
910
LABELS?: Labels;
11+
IGNORE?: TsIgnoreOptions;
1012
}
1113

1214
export function transformIncrByArguments(
@@ -35,6 +37,8 @@ export function transformIncrByArguments(
3537

3638
pushLabelsArgument(args, options?.LABELS);
3739

40+
pushIgnoreArgument(args, options?.IGNORE);
41+
3842
return args;
3943
}
4044

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { BlobStringReply, CommandArguments, DoubleReply, NumberReply, RedisArgument, RedisCommands, TuplesReply, UnwrapReply } from '@redis/client/dist/lib/RESP/types';
2-
import ADD from './ADD';
2+
import ADD, { TsIgnoreOptions } from './ADD';
33
import ALTER from './ALTER';
44
import CREATE from './CREATE';
55
import CREATERULE from './CREATERULE';
@@ -67,6 +67,12 @@ export default {
6767
revRange: REVRANGE
6868
} as const satisfies RedisCommands;
6969

70+
export function pushIgnoreArgument(args: Array<RedisArgument>, ignore?: TsIgnoreOptions) {
71+
if (ignore !== undefined) {
72+
args.push('IGNORE', ignore.maxTimeDiff.toString(), ignore.maxValDiff.toString());
73+
}
74+
}
75+
7076
export function pushRetentionArgument(args: Array<RedisArgument>, retention?: number) {
7177
if (retention !== undefined) {
7278
args.push('RETENTION', retention.toString());

0 commit comments

Comments
 (0)