From 3f25e25d00fc55a026eace8d86db2af0961ee0f5 Mon Sep 17 00:00:00 2001 From: Shaya Potter Date: Tue, 7 May 2024 14:47:01 +0300 Subject: [PATCH 1/5] CAE-193: add "IGNORE" options to time series commands (for v5 branch) --- packages/time-series/lib/commands/ADD.spec.ts | 34 +++++++++++++++++-- packages/time-series/lib/commands/ADD.ts | 6 ++++ .../time-series/lib/commands/ALTER.spec.ts | 34 +++++++++++++++++-- packages/time-series/lib/commands/ALTER.ts | 6 ++-- .../time-series/lib/commands/CREATE.spec.ts | 34 +++++++++++++++++-- packages/time-series/lib/commands/CREATE.ts | 7 +++- packages/time-series/lib/commands/index.ts | 12 ++++++- 7 files changed, 120 insertions(+), 13 deletions(-) diff --git a/packages/time-series/lib/commands/ADD.spec.ts b/packages/time-series/lib/commands/ADD.spec.ts index e9831d21d02..cb801f847d6 100644 --- a/packages/time-series/lib/commands/ADD.spec.ts +++ b/packages/time-series/lib/commands/ADD.spec.ts @@ -57,16 +57,44 @@ describe('TS.ADD', () => { ); }); - it('with RETENTION, ENCODING, CHUNK_SIZE, ON_DUPLICATE, LABELS', () => { + it('with IGNORE no values', () => { + assert.deepEqual( + ADD.transformArguments('key', '*', 1, { + IGNORE: { } + }), + ['TS.ADD', 'key', '*', '1', 'IGNORE', '0', '0'] + ) + }); + + it('with IGNORE with MAX_TIME_DIFF', () => { + assert.deepEqual( + ADD.transformArguments('key', '*', 1, { + IGNORE: { MAX_TIME_DIFF: 1} + }), + ['TS.ADD', 'key', '*', '1', 'IGNORE', '1', '0'] + ) + }); + + it('with IGNORE with MAX_VAL_DIFF', () => { + assert.deepEqual( + ADD.transformArguments('key', '*', 1, { + IGNORE: { MAX_VAL_DIFF: 1} + }), + ['TS.ADD', 'key', '*', '1', 'IGNORE', '0', '1'] + ) + }); + + it('with RETENTION, ENCODING, CHUNK_SIZE, ON_DUPLICATE, LABELS, IGNORE', () => { assert.deepEqual( ADD.transformArguments('key', '*', 1, { RETENTION: 1, ENCODING: TIME_SERIES_ENCODING.UNCOMPRESSED, CHUNK_SIZE: 1, ON_DUPLICATE: TIME_SERIES_DUPLICATE_POLICIES.BLOCK, - LABELS: { label: 'value' } + LABELS: { label: 'value' }, + IGNORE: { MAX_TIME_DIFF: 1, MAX_VAL_DIFF: 1} }), - ['TS.ADD', 'key', '*', '1', 'RETENTION', '1', 'ENCODING', 'UNCOMPRESSED', 'CHUNK_SIZE', '1', 'ON_DUPLICATE', 'BLOCK', 'LABELS', 'label', 'value'] + ['TS.ADD', 'key', '*', '1', 'RETENTION', '1', 'ENCODING', 'UNCOMPRESSED', 'CHUNK_SIZE', '1', 'ON_DUPLICATE', 'BLOCK', 'LABELS', 'label', 'value', 'IGNORE', '1', '1'] ); }); }); diff --git a/packages/time-series/lib/commands/ADD.ts b/packages/time-series/lib/commands/ADD.ts index b40a6912ca8..89b01ada47a 100644 --- a/packages/time-series/lib/commands/ADD.ts +++ b/packages/time-series/lib/commands/ADD.ts @@ -11,12 +11,18 @@ import { Timestamp } from '.'; +export interface TsIgnoreOptions { + MAX_TIME_DIFF: number; + MAX_VAL_DIFF: number; +} + export interface TsAddOptions { RETENTION?: number; ENCODING?: TimeSeriesEncoding; CHUNK_SIZE?: number; ON_DUPLICATE?: TimeSeriesDuplicatePolicies; LABELS?: Labels; + IGNORE?: TsIgnoreOptions; } export default { diff --git a/packages/time-series/lib/commands/ALTER.spec.ts b/packages/time-series/lib/commands/ALTER.spec.ts index b60bdece62e..b0d36bbac6e 100644 --- a/packages/time-series/lib/commands/ALTER.spec.ts +++ b/packages/time-series/lib/commands/ALTER.spec.ts @@ -48,15 +48,43 @@ describe('TS.ALTER', () => { ); }); - it('with RETENTION, CHUNK_SIZE, DUPLICATE_POLICY, LABELS', () => { + it('with IGNORE no values', () => { + assert.deepEqual( + ALTER.transformArguments('key', { + IGNORE: { } + }), + ['TS.ALTER', 'key', 'IGNORE', '0', '0'] + ) + }); + + it('with IGNORE with MAX_TIME_DIFF', () => { + assert.deepEqual( + ALTER.transformArguments('key', { + IGNORE: { MAX_TIME_DIFF: 1} + }), + ['TS.ALTER', 'key', 'IGNORE', '1', '0'] + ) + }); + + it('with IGNORE with MAX_VAL_DIFF', () => { + assert.deepEqual( + ALTER.transformArguments('key', { + IGNORE: { MAX_VAL_DIFF: 1} + }), + ['TS.ALTER', 'key', 'IGNORE', '0', '1'] + ) + }); + + it('with RETENTION, CHUNK_SIZE, DUPLICATE_POLICY, LABELS, IGNORE', () => { assert.deepEqual( ALTER.transformArguments('key', { RETENTION: 1, CHUNK_SIZE: 1, DUPLICATE_POLICY: TIME_SERIES_DUPLICATE_POLICIES.BLOCK, - LABELS: { label: 'value' } + LABELS: { label: 'value' }, + IGNORE: { MAX_TIME_DIFF: 1, MAX_VAL_DIFF: 1} }), - ['TS.ALTER', 'key', 'RETENTION', '1', 'CHUNK_SIZE', '1', 'DUPLICATE_POLICY', 'BLOCK', 'LABELS', 'label', 'value'] + ['TS.ALTER', 'key', 'RETENTION', '1', 'CHUNK_SIZE', '1', 'DUPLICATE_POLICY', 'BLOCK', 'LABELS', 'label', 'value', 'IGNORE', '1', '1'] ); }); }); diff --git a/packages/time-series/lib/commands/ALTER.ts b/packages/time-series/lib/commands/ALTER.ts index ae30799b2eb..f77edb5c43f 100644 --- a/packages/time-series/lib/commands/ALTER.ts +++ b/packages/time-series/lib/commands/ALTER.ts @@ -1,8 +1,8 @@ import { RedisArgument, SimpleStringReply, Command } from '@redis/client/dist/lib/RESP/types'; import { TsCreateOptions } from './CREATE'; -import { pushRetentionArgument, pushChunkSizeArgument, pushDuplicatePolicy, pushLabelsArgument } from '.'; +import { pushRetentionArgument, pushChunkSizeArgument, pushDuplicatePolicy, pushLabelsArgument, pushIgnoreArgument } from '.'; -export type TsAlterOptions = Pick; +export type TsAlterOptions = Pick; export default { FIRST_KEY_INDEX: 1, @@ -18,6 +18,8 @@ export default { pushLabelsArgument(args, options?.LABELS); + pushIgnoreArgument(args, options?.IGNORE); + return args; }, transformReply: undefined as unknown as () => SimpleStringReply<'OK'> diff --git a/packages/time-series/lib/commands/CREATE.spec.ts b/packages/time-series/lib/commands/CREATE.spec.ts index d400be8a035..9418b91e569 100644 --- a/packages/time-series/lib/commands/CREATE.spec.ts +++ b/packages/time-series/lib/commands/CREATE.spec.ts @@ -57,16 +57,44 @@ describe('TS.CREATE', () => { ); }); - it('with RETENTION, ENCODING, CHUNK_SIZE, DUPLICATE_POLICY, LABELS', () => { + it('with IGNORE no values', () => { + assert.deepEqual( + CREATE.transformArguments('key', { + IGNORE: { } + }), + ['TS.CREATE', 'key', 'IGNORE', '0', '0'] + ) + }); + + it('with IGNORE with MAX_TIME_DIFF', () => { + assert.deepEqual( + CREATE.transformArguments('key', { + IGNORE: { MAX_TIME_DIFF: 1} + }), + ['TS.CREATE', 'IGNORE', '1', '0'] + ) + }); + + it('with IGNORE with MAX_VAL_DIFF', () => { + assert.deepEqual( + CREATE.transformArguments('key', { + IGNORE: { MAX_VAL_DIFF: 1} + }), + ['TS.CREATE', 'IGNORE', '0', '1'] + ) + }); + + it('with RETENTION, ENCODING, CHUNK_SIZE, DUPLICATE_POLICY, LABELS, IGNORE', () => { assert.deepEqual( CREATE.transformArguments('key', { RETENTION: 1, ENCODING: TIME_SERIES_ENCODING.UNCOMPRESSED, CHUNK_SIZE: 1, DUPLICATE_POLICY: TIME_SERIES_DUPLICATE_POLICIES.BLOCK, - LABELS: { label: 'value' } + LABELS: { label: 'value' }, + IGNORE: { MAX_TIME_DIFF: 1, MAX_VAL_DIFF: 1} }), - ['TS.CREATE', 'key', 'RETENTION', '1', 'ENCODING', 'UNCOMPRESSED', 'CHUNK_SIZE', '1', 'DUPLICATE_POLICY', 'BLOCK', 'LABELS', 'label', 'value'] + ['TS.CREATE', 'key', 'RETENTION', '1', 'ENCODING', 'UNCOMPRESSED', 'CHUNK_SIZE', '1', 'DUPLICATE_POLICY', 'BLOCK', 'LABELS', 'label', 'value', 'IGNORE', '1', '1'] ); }); }); diff --git a/packages/time-series/lib/commands/CREATE.ts b/packages/time-series/lib/commands/CREATE.ts index b028a470277..abb84de12a2 100644 --- a/packages/time-series/lib/commands/CREATE.ts +++ b/packages/time-series/lib/commands/CREATE.ts @@ -7,8 +7,10 @@ import { TimeSeriesDuplicatePolicies, pushDuplicatePolicy, Labels, - pushLabelsArgument + pushLabelsArgument, + pushIgnoreArgument } from '.'; +import { TsIgnoreOptions } from './ADD'; export interface TsCreateOptions { RETENTION?: number; @@ -16,6 +18,7 @@ export interface TsCreateOptions { CHUNK_SIZE?: number; DUPLICATE_POLICY?: TimeSeriesDuplicatePolicies; LABELS?: Labels; + IGNORE?: TsIgnoreOptions; } export default { @@ -34,6 +37,8 @@ export default { pushLabelsArgument(args, options?.LABELS); + pushIgnoreArgument(args, options?.IGNORE); + return args; }, transformReply: undefined as unknown as () => SimpleStringReply<'OK'> diff --git a/packages/time-series/lib/commands/index.ts b/packages/time-series/lib/commands/index.ts index e9137a15a00..c66319d5dd7 100644 --- a/packages/time-series/lib/commands/index.ts +++ b/packages/time-series/lib/commands/index.ts @@ -1,5 +1,5 @@ import type { BlobStringReply, CommandArguments, DoubleReply, NumberReply, RedisArgument, RedisCommands, TuplesReply, UnwrapReply } from '@redis/client/dist/lib/RESP/types'; -import ADD from './ADD'; +import ADD, { TsIgnoreOptions } from './ADD'; import ALTER from './ALTER'; import CREATE from './CREATE'; import CREATERULE from './CREATERULE'; @@ -67,6 +67,16 @@ export default { revRange: REVRANGE } as const satisfies RedisCommands; +export function pushIgnoreArgument(args: Array, ignore?: TsIgnoreOptions) { + if (ignore !== undefined) { + args.push( + 'IGNORE', + ignore.MAX_TIME_DIFF ? ignore.MAX_TIME_DIFF.toString() : '0', + ignore.MAX_VAL_DIFF ? ignore.MAX_VAL_DIFF.toString() : '0' + ) + } +} + export function pushRetentionArgument(args: Array, retention?: number) { if (retention !== undefined) { args.push('RETENTION', retention.toString()); From 10f1b562d45a7297c8b2321522ac995d2d6a2b20 Mon Sep 17 00:00:00 2001 From: Shaya Potter Date: Sun, 19 May 2024 15:06:56 +0300 Subject: [PATCH 2/5] add INCR/DECR and modify tests to not test ignore on older version --- packages/time-series/lib/commands/ADD.spec.ts | 53 +++++++++--------- packages/time-series/lib/commands/ADD.ts | 9 ++- .../time-series/lib/commands/ALTER.spec.ts | 55 ++++++++++--------- .../time-series/lib/commands/CREATE.spec.ts | 55 ++++++++++--------- .../time-series/lib/commands/DECRBY.spec.ts | 31 +++++++++++ .../time-series/lib/commands/INCRBY.spec.ts | 31 +++++++++++ packages/time-series/lib/commands/INCRBY.ts | 6 +- 7 files changed, 158 insertions(+), 82 deletions(-) diff --git a/packages/time-series/lib/commands/ADD.spec.ts b/packages/time-series/lib/commands/ADD.spec.ts index cb801f847d6..0d29df06d0e 100644 --- a/packages/time-series/lib/commands/ADD.spec.ts +++ b/packages/time-series/lib/commands/ADD.spec.ts @@ -57,34 +57,36 @@ describe('TS.ADD', () => { ); }); - it('with IGNORE no values', () => { - assert.deepEqual( - ADD.transformArguments('key', '*', 1, { - IGNORE: { } - }), - ['TS.ADD', 'key', '*', '1', 'IGNORE', '0', '0'] - ) - }); + it ('with IGNORE', () => { + it('no values', () => { + assert.deepEqual( + ADD.transformArguments('key', '*', 1, { + IGNORE: { } + }), + ['TS.ADD', 'key', '*', '1', 'IGNORE', '0', '0'] + ) + }); - it('with IGNORE with MAX_TIME_DIFF', () => { - assert.deepEqual( - ADD.transformArguments('key', '*', 1, { - IGNORE: { MAX_TIME_DIFF: 1} - }), - ['TS.ADD', 'key', '*', '1', 'IGNORE', '1', '0'] - ) - }); + it('with MAX_TIME_DIFF', () => { + assert.deepEqual( + ADD.transformArguments('key', '*', 1, { + IGNORE: { MAX_TIME_DIFF: 1} + }), + ['TS.ADD', 'key', '*', '1', 'IGNORE', '1', '0'] + ) + }); - it('with IGNORE with MAX_VAL_DIFF', () => { - assert.deepEqual( - ADD.transformArguments('key', '*', 1, { - IGNORE: { MAX_VAL_DIFF: 1} - }), - ['TS.ADD', 'key', '*', '1', 'IGNORE', '0', '1'] - ) + it('with MAX_VAL_DIFF', () => { + assert.deepEqual( + ADD.transformArguments('key', '*', 1, { + IGNORE: { MAX_VAL_DIFF: 1} + }), + ['TS.ADD', 'key', '*', '1', 'IGNORE', '0', '1'] + ) + }); }); - it('with RETENTION, ENCODING, CHUNK_SIZE, ON_DUPLICATE, LABELS, IGNORE', () => { + it('with RETENTION, ENCODING, CHUNK_SIZE, ON_DUPLICATE, LABELS', () => { assert.deepEqual( ADD.transformArguments('key', '*', 1, { RETENTION: 1, @@ -92,9 +94,8 @@ describe('TS.ADD', () => { CHUNK_SIZE: 1, ON_DUPLICATE: TIME_SERIES_DUPLICATE_POLICIES.BLOCK, LABELS: { label: 'value' }, - IGNORE: { MAX_TIME_DIFF: 1, MAX_VAL_DIFF: 1} }), - ['TS.ADD', 'key', '*', '1', 'RETENTION', '1', 'ENCODING', 'UNCOMPRESSED', 'CHUNK_SIZE', '1', 'ON_DUPLICATE', 'BLOCK', 'LABELS', 'label', 'value', 'IGNORE', '1', '1'] + ['TS.ADD', 'key', '*', '1', 'RETENTION', '1', 'ENCODING', 'UNCOMPRESSED', 'CHUNK_SIZE', '1', 'ON_DUPLICATE', 'BLOCK', 'LABELS', 'label', 'value'] ); }); }); diff --git a/packages/time-series/lib/commands/ADD.ts b/packages/time-series/lib/commands/ADD.ts index 89b01ada47a..80bf8d970d1 100644 --- a/packages/time-series/lib/commands/ADD.ts +++ b/packages/time-series/lib/commands/ADD.ts @@ -8,12 +8,13 @@ import { TimeSeriesDuplicatePolicies, Labels, pushLabelsArgument, - Timestamp + Timestamp, + pushIgnoreArgument } from '.'; export interface TsIgnoreOptions { - MAX_TIME_DIFF: number; - MAX_VAL_DIFF: number; + MAX_TIME_DIFF?: number; + MAX_VAL_DIFF?: number; } export interface TsAddOptions { @@ -53,6 +54,8 @@ export default { pushLabelsArgument(args, options?.LABELS); + pushIgnoreArgument(args, options?.IGNORE); + return args; }, transformReply: undefined as unknown as () => NumberReply diff --git a/packages/time-series/lib/commands/ALTER.spec.ts b/packages/time-series/lib/commands/ALTER.spec.ts index b0d36bbac6e..c49e0b508d4 100644 --- a/packages/time-series/lib/commands/ALTER.spec.ts +++ b/packages/time-series/lib/commands/ALTER.spec.ts @@ -48,43 +48,46 @@ describe('TS.ALTER', () => { ); }); - it('with IGNORE no values', () => { - assert.deepEqual( - ALTER.transformArguments('key', { - IGNORE: { } - }), - ['TS.ALTER', 'key', 'IGNORE', '0', '0'] - ) - }); + it('with IGNORE', () => { + testUtils.isVersionGreaterThanHook([7, 4]); + + it('no values', () => { + assert.deepEqual( + ALTER.transformArguments('key', { + IGNORE: { } + }), + ['TS.ALTER', 'key', 'IGNORE', '0', '0'] + ) + }); - it('with IGNORE with MAX_TIME_DIFF', () => { - assert.deepEqual( - ALTER.transformArguments('key', { - IGNORE: { MAX_TIME_DIFF: 1} - }), - ['TS.ALTER', 'key', 'IGNORE', '1', '0'] - ) - }); + it('with MAX_TIME_DIFF', () => { + assert.deepEqual( + ALTER.transformArguments('key', { + IGNORE: { MAX_TIME_DIFF: 1} + }), + ['TS.ALTER', 'key', 'IGNORE', '1', '0'] + ) + }); - it('with IGNORE with MAX_VAL_DIFF', () => { - assert.deepEqual( - ALTER.transformArguments('key', { - IGNORE: { MAX_VAL_DIFF: 1} - }), - ['TS.ALTER', 'key', 'IGNORE', '0', '1'] - ) + it('with MAX_VAL_DIFF', () => { + assert.deepEqual( + ALTER.transformArguments('key', { + IGNORE: { MAX_VAL_DIFF: 1} + }), + ['TS.ALTER', 'key', 'IGNORE', '0', '1'] + ) + }); }); - it('with RETENTION, CHUNK_SIZE, DUPLICATE_POLICY, LABELS, IGNORE', () => { + it('with RETENTION, CHUNK_SIZE, DUPLICATE_POLICY, LABELS', () => { assert.deepEqual( ALTER.transformArguments('key', { RETENTION: 1, CHUNK_SIZE: 1, DUPLICATE_POLICY: TIME_SERIES_DUPLICATE_POLICIES.BLOCK, LABELS: { label: 'value' }, - IGNORE: { MAX_TIME_DIFF: 1, MAX_VAL_DIFF: 1} }), - ['TS.ALTER', 'key', 'RETENTION', '1', 'CHUNK_SIZE', '1', 'DUPLICATE_POLICY', 'BLOCK', 'LABELS', 'label', 'value', 'IGNORE', '1', '1'] + ['TS.ALTER', 'key', 'RETENTION', '1', 'CHUNK_SIZE', '1', 'DUPLICATE_POLICY', 'BLOCK', 'LABELS', 'label', 'value'] ); }); }); diff --git a/packages/time-series/lib/commands/CREATE.spec.ts b/packages/time-series/lib/commands/CREATE.spec.ts index 9418b91e569..6a6a408d5c5 100644 --- a/packages/time-series/lib/commands/CREATE.spec.ts +++ b/packages/time-series/lib/commands/CREATE.spec.ts @@ -57,34 +57,38 @@ describe('TS.CREATE', () => { ); }); - it('with IGNORE no values', () => { - assert.deepEqual( - CREATE.transformArguments('key', { - IGNORE: { } - }), - ['TS.CREATE', 'key', 'IGNORE', '0', '0'] - ) - }); + it('with IGNORE', () => { + testUtils.isVersionGreaterThanHook([7, 4]); + + it('no values', () => { + assert.deepEqual( + CREATE.transformArguments('key', { + IGNORE: { } + }), + ['TS.CREATE', 'key', 'IGNORE', '0', '0'] + ) + }); - it('with IGNORE with MAX_TIME_DIFF', () => { - assert.deepEqual( - CREATE.transformArguments('key', { - IGNORE: { MAX_TIME_DIFF: 1} - }), - ['TS.CREATE', 'IGNORE', '1', '0'] - ) - }); + it('with MAX_TIME_DIFF', () => { + assert.deepEqual( + CREATE.transformArguments('key', { + IGNORE: { MAX_TIME_DIFF: 1} + }), + ['TS.CREATE', 'IGNORE', '1', '0'] + ) + }); - it('with IGNORE with MAX_VAL_DIFF', () => { - assert.deepEqual( - CREATE.transformArguments('key', { - IGNORE: { MAX_VAL_DIFF: 1} - }), - ['TS.CREATE', 'IGNORE', '0', '1'] - ) + it('with MAX_VAL_DIFF', () => { + assert.deepEqual( + CREATE.transformArguments('key', { + IGNORE: { MAX_VAL_DIFF: 1} + }), + ['TS.CREATE', 'IGNORE', '0', '1'] + ) + }); }); - it('with RETENTION, ENCODING, CHUNK_SIZE, DUPLICATE_POLICY, LABELS, IGNORE', () => { + it('with RETENTION, ENCODING, CHUNK_SIZE, DUPLICATE_POLICY, LABELS', () => { assert.deepEqual( CREATE.transformArguments('key', { RETENTION: 1, @@ -92,9 +96,8 @@ describe('TS.CREATE', () => { CHUNK_SIZE: 1, DUPLICATE_POLICY: TIME_SERIES_DUPLICATE_POLICIES.BLOCK, LABELS: { label: 'value' }, - IGNORE: { MAX_TIME_DIFF: 1, MAX_VAL_DIFF: 1} }), - ['TS.CREATE', 'key', 'RETENTION', '1', 'ENCODING', 'UNCOMPRESSED', 'CHUNK_SIZE', '1', 'DUPLICATE_POLICY', 'BLOCK', 'LABELS', 'label', 'value', 'IGNORE', '1', '1'] + ['TS.CREATE', 'key', 'RETENTION', '1', 'ENCODING', 'UNCOMPRESSED', 'CHUNK_SIZE', '1', 'DUPLICATE_POLICY', 'BLOCK', 'LABELS', 'label', 'value'] ); }); }); diff --git a/packages/time-series/lib/commands/DECRBY.spec.ts b/packages/time-series/lib/commands/DECRBY.spec.ts index f9e482bcae6..9633a1607f1 100644 --- a/packages/time-series/lib/commands/DECRBY.spec.ts +++ b/packages/time-series/lib/commands/DECRBY.spec.ts @@ -56,6 +56,37 @@ describe('TS.DECRBY', () => { ); }); + it ('with IGNORE', () => { + testUtils.isVersionGreaterThanHook([7, 4]); + + it('no values', () => { + assert.deepEqual( + DECRBY.transformArguments('key', 1, { + IGNORE: { } + }), + ['TS.DECRBY', 'key', '1', 'IGNORE', '0', '0'] + ) + }); + + it('MAX_TIME_DIFF', () => { + assert.deepEqual( + DECRBY.transformArguments('key', 1, { + IGNORE: { MAX_TIME_DIFF: 1} + }), + ['TS.DECRBY', 'key', '1', 'IGNORE', '1', '0'] + ) + }); + + it('MAX_VAL_DIFF', () => { + assert.deepEqual( + DECRBY.transformArguments('key', 1, { + IGNORE: { MAX_VAL_DIFF: 1} + }), + ['TS.DECRBY', 'key', '1', 'IGNORE', '0', '1'] + ) + }); + }); + it('with TIMESTAMP, RETENTION, UNCOMPRESSED, CHUNK_SIZE and LABELS', () => { assert.deepEqual( DECRBY.transformArguments('key', 1, { diff --git a/packages/time-series/lib/commands/INCRBY.spec.ts b/packages/time-series/lib/commands/INCRBY.spec.ts index 463bf930104..d8d394cf3fa 100644 --- a/packages/time-series/lib/commands/INCRBY.spec.ts +++ b/packages/time-series/lib/commands/INCRBY.spec.ts @@ -65,6 +65,37 @@ describe('TS.INCRBY', () => { ); }); + it ('with IGNORE', () => { + testUtils.isVersionGreaterThanHook([7, 4]); + + it('no values', () => { + assert.deepEqual( + INCRBY.transformArguments('key', 1, { + IGNORE: { } + }), + ['TS.INCRBY', 'key', '1', 'IGNORE', '0', '0'] + ) + }); + + it('MAX_TIME_DIFF', () => { + assert.deepEqual( + INCRBY.transformArguments('key', 1, { + IGNORE: { MAX_TIME_DIFF: 1} + }), + ['TS.INCRBY', 'key', '1', 'IGNORE', '1', '0'] + ) + }); + + it('MAX_VAL_DIFF', () => { + assert.deepEqual( + INCRBY.transformArguments('key', 1, { + IGNORE: { MAX_VAL_DIFF: 1} + }), + ['TS.INCRBY', 'key', '1', 'IGNORE', '0', '1'] + ) + }); + }); + it('with TIMESTAMP, RETENTION, UNCOMPRESSED, CHUNK_SIZE and LABELS', () => { assert.deepEqual( INCRBY.transformArguments('key', 1, { diff --git a/packages/time-series/lib/commands/INCRBY.ts b/packages/time-series/lib/commands/INCRBY.ts index ece5defee6a..3160d3906d3 100644 --- a/packages/time-series/lib/commands/INCRBY.ts +++ b/packages/time-series/lib/commands/INCRBY.ts @@ -1,5 +1,6 @@ import { RedisArgument, NumberReply, Command } from '@redis/client/dist/lib/RESP/types'; -import { Timestamp, transformTimestampArgument, pushRetentionArgument, pushChunkSizeArgument, Labels, pushLabelsArgument } from '.'; +import { Timestamp, transformTimestampArgument, pushRetentionArgument, pushChunkSizeArgument, Labels, pushLabelsArgument, pushIgnoreArgument } from '.'; +import { TsIgnoreOptions } from './ADD'; export interface TsIncrByOptions { TIMESTAMP?: Timestamp; @@ -7,6 +8,7 @@ export interface TsIncrByOptions { UNCOMPRESSED?: boolean; CHUNK_SIZE?: number; LABELS?: Labels; + IGNORE?: TsIgnoreOptions; } export function transformIncrByArguments( @@ -35,6 +37,8 @@ export function transformIncrByArguments( pushLabelsArgument(args, options?.LABELS); + pushIgnoreArgument(args, options?.IGNORE); + return args; } From dccadbfbc18610adda810545e64589211e5079b3 Mon Sep 17 00:00:00 2001 From: Shaya Potter Date: Thu, 6 Jun 2024 23:43:41 +0300 Subject: [PATCH 3/5] require maxTimeDiff/maxValDiff to be specified also rename them --- packages/time-series/lib/commands/ADD.ts | 4 ++-- packages/time-series/lib/commands/index.ts | 6 +----- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/packages/time-series/lib/commands/ADD.ts b/packages/time-series/lib/commands/ADD.ts index 80bf8d970d1..1842dcfc346 100644 --- a/packages/time-series/lib/commands/ADD.ts +++ b/packages/time-series/lib/commands/ADD.ts @@ -13,8 +13,8 @@ import { } from '.'; export interface TsIgnoreOptions { - MAX_TIME_DIFF?: number; - MAX_VAL_DIFF?: number; + maxTimeDiff: number; + maxValDiff: number; } export interface TsAddOptions { diff --git a/packages/time-series/lib/commands/index.ts b/packages/time-series/lib/commands/index.ts index c66319d5dd7..84976ca7b31 100644 --- a/packages/time-series/lib/commands/index.ts +++ b/packages/time-series/lib/commands/index.ts @@ -69,11 +69,7 @@ export default { export function pushIgnoreArgument(args: Array, ignore?: TsIgnoreOptions) { if (ignore !== undefined) { - args.push( - 'IGNORE', - ignore.MAX_TIME_DIFF ? ignore.MAX_TIME_DIFF.toString() : '0', - ignore.MAX_VAL_DIFF ? ignore.MAX_VAL_DIFF.toString() : '0' - ) + args.push('IGNORE', ignore.maxTimeDiff.toString(), ignore.maxValDiff.toString()); } } From 5cd8ab656f77fe51f664494711f704b0078d4568 Mon Sep 17 00:00:00 2001 From: Shaya Potter Date: Mon, 8 Jul 2024 11:06:38 +0300 Subject: [PATCH 4/5] fix add/ignore test after api change --- packages/time-series/lib/commands/ADD.spec.ts | 40 ++++++------------- 1 file changed, 12 insertions(+), 28 deletions(-) diff --git a/packages/time-series/lib/commands/ADD.spec.ts b/packages/time-series/lib/commands/ADD.spec.ts index 0d29df06d0e..7dcf031c2b2 100644 --- a/packages/time-series/lib/commands/ADD.spec.ts +++ b/packages/time-series/lib/commands/ADD.spec.ts @@ -58,35 +58,18 @@ describe('TS.ADD', () => { }); it ('with IGNORE', () => { - it('no values', () => { - assert.deepEqual( - ADD.transformArguments('key', '*', 1, { - IGNORE: { } - }), - ['TS.ADD', 'key', '*', '1', 'IGNORE', '0', '0'] - ) - }); - - it('with MAX_TIME_DIFF', () => { - assert.deepEqual( - ADD.transformArguments('key', '*', 1, { - IGNORE: { MAX_TIME_DIFF: 1} - }), - ['TS.ADD', 'key', '*', '1', 'IGNORE', '1', '0'] - ) - }); - - it('with MAX_VAL_DIFF', () => { - assert.deepEqual( - ADD.transformArguments('key', '*', 1, { - IGNORE: { MAX_VAL_DIFF: 1} - }), - ['TS.ADD', 'key', '*', '1', 'IGNORE', '0', '1'] - ) - }); + assert.deepEqual( + ADD.transformArguments('key', '*', 1, { + IGNORE: { + maxTimeDiff: 1, + maxValDiff: 1 + } + }), + ['TS.ADD', 'key', '*', '1', 'IGNORE', '1', '1'] + ) }); - it('with RETENTION, ENCODING, CHUNK_SIZE, ON_DUPLICATE, LABELS', () => { + it('with RETENTION, ENCODING, CHUNK_SIZE, ON_DUPLICATE, LABELS, IGNORE', () => { assert.deepEqual( ADD.transformArguments('key', '*', 1, { RETENTION: 1, @@ -94,8 +77,9 @@ describe('TS.ADD', () => { CHUNK_SIZE: 1, ON_DUPLICATE: TIME_SERIES_DUPLICATE_POLICIES.BLOCK, LABELS: { label: 'value' }, + IGNORE: { maxTimeDiff: 1, maxValDiff: 1} }), - ['TS.ADD', 'key', '*', '1', 'RETENTION', '1', 'ENCODING', 'UNCOMPRESSED', 'CHUNK_SIZE', '1', 'ON_DUPLICATE', 'BLOCK', 'LABELS', 'label', 'value'] + ['TS.ADD', 'key', '*', '1', 'RETENTION', '1', 'ENCODING', 'UNCOMPRESSED', 'CHUNK_SIZE', '1', 'ON_DUPLICATE', 'BLOCK', 'LABELS', 'label', 'value', 'IGNORE', '1', '1'] ); }); }); From 230aebfd6089f29873dab922a250d30dcd1dbf5d Mon Sep 17 00:00:00 2001 From: Shaya Potter Date: Mon, 8 Jul 2024 11:16:36 +0300 Subject: [PATCH 5/5] update tests for api change in IGNORE option --- .../time-series/lib/commands/ALTER.spec.ts | 44 ++++++------------ .../time-series/lib/commands/CREATE.spec.ts | 44 ++++++------------ .../time-series/lib/commands/DECRBY.spec.ts | 46 ++++++------------- .../time-series/lib/commands/INCRBY.spec.ts | 44 ++++++------------ 4 files changed, 53 insertions(+), 125 deletions(-) diff --git a/packages/time-series/lib/commands/ALTER.spec.ts b/packages/time-series/lib/commands/ALTER.spec.ts index c49e0b508d4..4998dcb1a49 100644 --- a/packages/time-series/lib/commands/ALTER.spec.ts +++ b/packages/time-series/lib/commands/ALTER.spec.ts @@ -48,46 +48,28 @@ describe('TS.ALTER', () => { ); }); - it('with IGNORE', () => { - testUtils.isVersionGreaterThanHook([7, 4]); - - it('no values', () => { - assert.deepEqual( - ALTER.transformArguments('key', { - IGNORE: { } - }), - ['TS.ALTER', 'key', 'IGNORE', '0', '0'] - ) - }); - - it('with MAX_TIME_DIFF', () => { - assert.deepEqual( - ALTER.transformArguments('key', { - IGNORE: { MAX_TIME_DIFF: 1} - }), - ['TS.ALTER', 'key', 'IGNORE', '1', '0'] - ) - }); - - it('with MAX_VAL_DIFF', () => { - assert.deepEqual( - ALTER.transformArguments('key', { - IGNORE: { MAX_VAL_DIFF: 1} - }), - ['TS.ALTER', 'key', 'IGNORE', '0', '1'] - ) - }); + it('with IGNORE', () => { + assert.deepEqual( + ALTER.transformArguments('key', { + IGNORE: { + maxTimeDiff: 1, + maxValDiff: 1 + } + }), + ['TS.ALTER', 'key', 'IGNORE', '1', '1'] + ) }); - it('with RETENTION, CHUNK_SIZE, DUPLICATE_POLICY, LABELS', () => { + it('with RETENTION, CHUNK_SIZE, DUPLICATE_POLICY, LABELS, IGNORE', () => { assert.deepEqual( ALTER.transformArguments('key', { RETENTION: 1, CHUNK_SIZE: 1, DUPLICATE_POLICY: TIME_SERIES_DUPLICATE_POLICIES.BLOCK, LABELS: { label: 'value' }, + IGNORE: { maxTimeDiff: 1, maxValDiff: 1} }), - ['TS.ALTER', 'key', 'RETENTION', '1', 'CHUNK_SIZE', '1', 'DUPLICATE_POLICY', 'BLOCK', 'LABELS', 'label', 'value'] + ['TS.ALTER', 'key', 'RETENTION', '1', 'CHUNK_SIZE', '1', 'DUPLICATE_POLICY', 'BLOCK', 'LABELS', 'label', 'value', 'IGNORE', '1', '1'] ); }); }); diff --git a/packages/time-series/lib/commands/CREATE.spec.ts b/packages/time-series/lib/commands/CREATE.spec.ts index 6a6a408d5c5..abe198970b9 100644 --- a/packages/time-series/lib/commands/CREATE.spec.ts +++ b/packages/time-series/lib/commands/CREATE.spec.ts @@ -57,38 +57,19 @@ describe('TS.CREATE', () => { ); }); - it('with IGNORE', () => { - testUtils.isVersionGreaterThanHook([7, 4]); - - it('no values', () => { - assert.deepEqual( - CREATE.transformArguments('key', { - IGNORE: { } - }), - ['TS.CREATE', 'key', 'IGNORE', '0', '0'] - ) - }); - - it('with MAX_TIME_DIFF', () => { - assert.deepEqual( - CREATE.transformArguments('key', { - IGNORE: { MAX_TIME_DIFF: 1} - }), - ['TS.CREATE', 'IGNORE', '1', '0'] - ) - }); - - it('with MAX_VAL_DIFF', () => { - assert.deepEqual( - CREATE.transformArguments('key', { - IGNORE: { MAX_VAL_DIFF: 1} - }), - ['TS.CREATE', 'IGNORE', '0', '1'] - ) - }); + it('with IGNORE', () => { + assert.deepEqual( + CREATE.transformArguments('key', { + IGNORE: { + maxTimeDiff: 1, + maxValDiff: 1 + } + }), + ['TS.CREATE', 'key', 'IGNORE', '1', '1'] + ) }); - it('with RETENTION, ENCODING, CHUNK_SIZE, DUPLICATE_POLICY, LABELS', () => { + it('with RETENTION, ENCODING, CHUNK_SIZE, DUPLICATE_POLICY, LABELS, IGNORE', () => { assert.deepEqual( CREATE.transformArguments('key', { RETENTION: 1, @@ -96,8 +77,9 @@ describe('TS.CREATE', () => { CHUNK_SIZE: 1, DUPLICATE_POLICY: TIME_SERIES_DUPLICATE_POLICIES.BLOCK, LABELS: { label: 'value' }, + IGNORE: { maxTimeDiff: 1, maxValDiff: 1} }), - ['TS.CREATE', 'key', 'RETENTION', '1', 'ENCODING', 'UNCOMPRESSED', 'CHUNK_SIZE', '1', 'DUPLICATE_POLICY', 'BLOCK', 'LABELS', 'label', 'value'] + ['TS.CREATE', 'key', 'RETENTION', '1', 'ENCODING', 'UNCOMPRESSED', 'CHUNK_SIZE', '1', 'DUPLICATE_POLICY', 'BLOCK', 'LABELS', 'label', 'value', 'IGNORE', '1', '1'] ); }); }); diff --git a/packages/time-series/lib/commands/DECRBY.spec.ts b/packages/time-series/lib/commands/DECRBY.spec.ts index 9633a1607f1..dbce98b2acd 100644 --- a/packages/time-series/lib/commands/DECRBY.spec.ts +++ b/packages/time-series/lib/commands/DECRBY.spec.ts @@ -56,37 +56,18 @@ describe('TS.DECRBY', () => { ); }); - it ('with IGNORE', () => { - testUtils.isVersionGreaterThanHook([7, 4]); - - it('no values', () => { - assert.deepEqual( - DECRBY.transformArguments('key', 1, { - IGNORE: { } - }), - ['TS.DECRBY', 'key', '1', 'IGNORE', '0', '0'] - ) - }); - - it('MAX_TIME_DIFF', () => { - assert.deepEqual( - DECRBY.transformArguments('key', 1, { - IGNORE: { MAX_TIME_DIFF: 1} - }), - ['TS.DECRBY', 'key', '1', 'IGNORE', '1', '0'] - ) - }); - - it('MAX_VAL_DIFF', () => { - assert.deepEqual( - DECRBY.transformArguments('key', 1, { - IGNORE: { MAX_VAL_DIFF: 1} - }), - ['TS.DECRBY', 'key', '1', 'IGNORE', '0', '1'] - ) - }); + it ('with IGNORE', () => { + assert.deepEqual( + DECRBY.transformArguments('key', 1, { + IGNORE: { + maxTimeDiff: 1, + maxValDiff: 1 + } + }), + ['TS.DECRBY', 'key', '1', 'IGNORE', '1', '1'] + ) }); - + it('with TIMESTAMP, RETENTION, UNCOMPRESSED, CHUNK_SIZE and LABELS', () => { assert.deepEqual( DECRBY.transformArguments('key', 1, { @@ -94,9 +75,10 @@ describe('TS.DECRBY', () => { RETENTION: 1, UNCOMPRESSED: true, CHUNK_SIZE: 2, - LABELS: { label: 'value' } + LABELS: { label: 'value' }, + IGNORE: { maxTimeDiff: 1, maxValDiff: 1 } }), - ['TS.DECRBY', 'key', '1', 'TIMESTAMP', '*', 'RETENTION', '1', 'UNCOMPRESSED', 'CHUNK_SIZE', '2', 'LABELS', 'label', 'value'] + ['TS.DECRBY', 'key', '1', 'TIMESTAMP', '*', 'RETENTION', '1', 'UNCOMPRESSED', 'CHUNK_SIZE', '2', 'LABELS', 'label', 'value', 'IGNORE', '1', '1'] ); }); }); diff --git a/packages/time-series/lib/commands/INCRBY.spec.ts b/packages/time-series/lib/commands/INCRBY.spec.ts index d8d394cf3fa..33163a72c82 100644 --- a/packages/time-series/lib/commands/INCRBY.spec.ts +++ b/packages/time-series/lib/commands/INCRBY.spec.ts @@ -66,36 +66,17 @@ describe('TS.INCRBY', () => { }); it ('with IGNORE', () => { - testUtils.isVersionGreaterThanHook([7, 4]); - - it('no values', () => { - assert.deepEqual( - INCRBY.transformArguments('key', 1, { - IGNORE: { } - }), - ['TS.INCRBY', 'key', '1', 'IGNORE', '0', '0'] - ) - }); - - it('MAX_TIME_DIFF', () => { - assert.deepEqual( - INCRBY.transformArguments('key', 1, { - IGNORE: { MAX_TIME_DIFF: 1} - }), - ['TS.INCRBY', 'key', '1', 'IGNORE', '1', '0'] - ) - }); - - it('MAX_VAL_DIFF', () => { - assert.deepEqual( - INCRBY.transformArguments('key', 1, { - IGNORE: { MAX_VAL_DIFF: 1} - }), - ['TS.INCRBY', 'key', '1', 'IGNORE', '0', '1'] - ) - }); + assert.deepEqual( + INCRBY.transformArguments('key', 1, { + IGNORE: { + maxTimeDiff: 1, + maxValDiff: 1 + } + }), + ['TS.INCRBY', 'key', '1', 'IGNORE', '1', '1'] + ) }); - + it('with TIMESTAMP, RETENTION, UNCOMPRESSED, CHUNK_SIZE and LABELS', () => { assert.deepEqual( INCRBY.transformArguments('key', 1, { @@ -103,10 +84,11 @@ describe('TS.INCRBY', () => { RETENTION: 1, UNCOMPRESSED: true, CHUNK_SIZE: 1, - LABELS: { label: 'value' } + LABELS: { label: 'value' }, + IGNORE: { maxTimeDiff: 1, maxValDiff: 1 } }), ['TS.INCRBY', 'key', '1', 'TIMESTAMP', '*', 'RETENTION', '1', 'UNCOMPRESSED', - 'CHUNK_SIZE', '1', 'LABELS', 'label', 'value'] + 'CHUNK_SIZE', '1', 'LABELS', 'label', 'value', 'IGNORE', '1', '1'] ); }); });