Skip to content

CAE-193: add "IGNORE" options to time series commands (for v5 branch) #2753

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions packages/time-series/lib/commands/ADD.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,29 @@ describe('TS.ADD', () => {
);
});

it('with RETENTION, ENCODING, CHUNK_SIZE, ON_DUPLICATE, LABELS', () => {
it ('with IGNORE', () => {
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, 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: { 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']
);
});
});
Expand Down
11 changes: 10 additions & 1 deletion packages/time-series/lib/commands/ADD.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,22 @@ import {
TimeSeriesDuplicatePolicies,
Labels,
pushLabelsArgument,
Timestamp
Timestamp,
pushIgnoreArgument
} from '.';

export interface TsIgnoreOptions {
maxTimeDiff: number;
maxValDiff: number;
}

export interface TsAddOptions {
RETENTION?: number;
ENCODING?: TimeSeriesEncoding;
CHUNK_SIZE?: number;
ON_DUPLICATE?: TimeSeriesDuplicatePolicies;
LABELS?: Labels;
IGNORE?: TsIgnoreOptions;
}

export default {
Expand Down Expand Up @@ -47,6 +54,8 @@ export default {

pushLabelsArgument(args, options?.LABELS);

pushIgnoreArgument(args, options?.IGNORE);

return args;
},
transformReply: undefined as unknown as () => NumberReply
Expand Down
19 changes: 16 additions & 3 deletions packages/time-series/lib/commands/ALTER.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,28 @@ describe('TS.ALTER', () => {
);
});

it('with RETENTION, CHUNK_SIZE, DUPLICATE_POLICY, LABELS', () => {
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, 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: { 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']
);
});
});
Expand Down
6 changes: 4 additions & 2 deletions packages/time-series/lib/commands/ALTER.ts
Original file line number Diff line number Diff line change
@@ -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<TsCreateOptions, 'RETENTION' | 'CHUNK_SIZE' | 'DUPLICATE_POLICY' | 'LABELS'>;
export type TsAlterOptions = Pick<TsCreateOptions, 'RETENTION' | 'CHUNK_SIZE' | 'DUPLICATE_POLICY' | 'LABELS' | 'IGNORE'>;

export default {
FIRST_KEY_INDEX: 1,
Expand All @@ -18,6 +18,8 @@ export default {

pushLabelsArgument(args, options?.LABELS);

pushIgnoreArgument(args, options?.IGNORE);

return args;
},
transformReply: undefined as unknown as () => SimpleStringReply<'OK'>
Expand Down
19 changes: 16 additions & 3 deletions packages/time-series/lib/commands/CREATE.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,29 @@ describe('TS.CREATE', () => {
);
});

it('with RETENTION, ENCODING, CHUNK_SIZE, DUPLICATE_POLICY, LABELS', () => {
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, 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: { 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']
);
});
});
Expand Down
7 changes: 6 additions & 1 deletion packages/time-series/lib/commands/CREATE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@ import {
TimeSeriesDuplicatePolicies,
pushDuplicatePolicy,
Labels,
pushLabelsArgument
pushLabelsArgument,
pushIgnoreArgument
} from '.';
import { TsIgnoreOptions } from './ADD';

export interface TsCreateOptions {
RETENTION?: number;
ENCODING?: TimeSeriesEncoding;
CHUNK_SIZE?: number;
DUPLICATE_POLICY?: TimeSeriesDuplicatePolicies;
LABELS?: Labels;
IGNORE?: TsIgnoreOptions;
}

export default {
Expand All @@ -34,6 +37,8 @@ export default {

pushLabelsArgument(args, options?.LABELS);

pushIgnoreArgument(args, options?.IGNORE);

return args;
},
transformReply: undefined as unknown as () => SimpleStringReply<'OK'>
Expand Down
17 changes: 15 additions & 2 deletions packages/time-series/lib/commands/DECRBY.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,29 @@ describe('TS.DECRBY', () => {
);
});

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, {
TIMESTAMP: '*',
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']
);
});
});
Expand Down
17 changes: 15 additions & 2 deletions packages/time-series/lib/commands/INCRBY.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,30 @@ describe('TS.INCRBY', () => {
);
});

it ('with IGNORE', () => {
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, {
TIMESTAMP: '*',
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']
);
});
});
Expand Down
6 changes: 5 additions & 1 deletion packages/time-series/lib/commands/INCRBY.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
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;
RETENTION?: number;
UNCOMPRESSED?: boolean;
CHUNK_SIZE?: number;
LABELS?: Labels;
IGNORE?: TsIgnoreOptions;
}

export function transformIncrByArguments(
Expand Down Expand Up @@ -35,6 +37,8 @@ export function transformIncrByArguments(

pushLabelsArgument(args, options?.LABELS);

pushIgnoreArgument(args, options?.IGNORE);

return args;
}

Expand Down
8 changes: 7 additions & 1 deletion packages/time-series/lib/commands/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -67,6 +67,12 @@ export default {
revRange: REVRANGE
} as const satisfies RedisCommands;

export function pushIgnoreArgument(args: Array<RedisArgument>, ignore?: TsIgnoreOptions) {
if (ignore !== undefined) {
args.push('IGNORE', ignore.maxTimeDiff.toString(), ignore.maxValDiff.toString());
}
}

export function pushRetentionArgument(args: Array<RedisArgument>, retention?: number) {
if (retention !== undefined) {
args.push('RETENTION', retention.toString());
Expand Down