You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-04 15:02:09 +03:00
CAE-193: add "IGNORE" options to time series commands (for v4 branch) (#2752)
This commit is contained in:
@@ -57,16 +57,26 @@ describe('ADD', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('with RETENTION, ENCODING, CHUNK_SIZE, ON_DUPLICATE, LABELS', () => {
|
||||
it('with IGNORE', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', '*', 1, {
|
||||
IGNORE: { MAX_TIME_DIFF: 1, MAX_VAL_DIFF: 1}
|
||||
}),
|
||||
['TS.ADD', 'key', '*', '1', 'IGNORE', '1', '1']
|
||||
)
|
||||
});
|
||||
|
||||
it('with RETENTION, ENCODING, CHUNK_SIZE, ON_DUPLICATE, LABELS, IGNORE', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', '*', 1, {
|
||||
RETENTION: 1,
|
||||
ENCODING: TimeSeriesEncoding.UNCOMPRESSED,
|
||||
CHUNK_SIZE: 1,
|
||||
ON_DUPLICATE: TimeSeriesDuplicatePolicies.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']
|
||||
);
|
||||
});
|
||||
});
|
||||
|
@@ -8,14 +8,21 @@ import {
|
||||
Labels,
|
||||
pushLabelsArgument,
|
||||
Timestamp,
|
||||
pushIgnoreArgument,
|
||||
} from '.';
|
||||
|
||||
export interface TsIgnoreOptions {
|
||||
MAX_TIME_DIFF: number;
|
||||
MAX_VAL_DIFF: number;
|
||||
}
|
||||
|
||||
interface AddOptions {
|
||||
RETENTION?: number;
|
||||
ENCODING?: TimeSeriesEncoding;
|
||||
CHUNK_SIZE?: number;
|
||||
ON_DUPLICATE?: TimeSeriesDuplicatePolicies;
|
||||
LABELS?: Labels;
|
||||
IGNORE?: TsIgnoreOptions;
|
||||
}
|
||||
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
@@ -40,6 +47,8 @@ export function transformArguments(key: string, timestamp: Timestamp, value: num
|
||||
|
||||
pushLabelsArgument(args, options?.LABELS);
|
||||
|
||||
pushIgnoreArgument(args, options?.IGNORE);
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
|
@@ -48,15 +48,25 @@ describe('ALTER', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('with RETENTION, CHUNK_SIZE, DUPLICATE_POLICY, LABELS', () => {
|
||||
it('with IGNORE with MAX_TIME_DIFF', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', {
|
||||
IGNORE: { MAX_TIME_DIFF: 1, MAX_VAL_DIFF: 1}
|
||||
}),
|
||||
['TS.ALTER', 'key', 'IGNORE', '1', '1']
|
||||
)
|
||||
});
|
||||
|
||||
it('with RETENTION, CHUNK_SIZE, DUPLICATE_POLICY, LABELS, IGNORE', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', {
|
||||
RETENTION: 1,
|
||||
CHUNK_SIZE: 1,
|
||||
DUPLICATE_POLICY: TimeSeriesDuplicatePolicies.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']
|
||||
);
|
||||
});
|
||||
});
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import { pushRetentionArgument, Labels, pushLabelsArgument, TimeSeriesDuplicatePolicies, pushChunkSizeArgument, pushDuplicatePolicy } from '.';
|
||||
import { pushRetentionArgument, Labels, pushLabelsArgument, TimeSeriesDuplicatePolicies, pushChunkSizeArgument, pushDuplicatePolicy, pushIgnoreArgument } from '.';
|
||||
import { TsIgnoreOptions } from './ADD';
|
||||
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
@@ -7,6 +8,7 @@ interface AlterOptions {
|
||||
CHUNK_SIZE?: number;
|
||||
DUPLICATE_POLICY?: TimeSeriesDuplicatePolicies;
|
||||
LABELS?: Labels;
|
||||
IGNORE?: TsIgnoreOptions;
|
||||
}
|
||||
|
||||
export function transformArguments(key: string, options?: AlterOptions): Array<string> {
|
||||
@@ -20,6 +22,8 @@ export function transformArguments(key: string, options?: AlterOptions): Array<s
|
||||
|
||||
pushLabelsArgument(args, options?.LABELS);
|
||||
|
||||
pushIgnoreArgument(args, options?.IGNORE);
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
|
@@ -56,17 +56,27 @@ describe('CREATE', () => {
|
||||
['TS.CREATE', 'key', 'LABELS', 'label', 'value']
|
||||
);
|
||||
});
|
||||
|
||||
it('with IGNORE with MAX_TIME_DIFF', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', {
|
||||
IGNORE: { MAX_TIME_DIFF: 1, MAX_VAL_DIFF: 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(
|
||||
transformArguments('key', {
|
||||
RETENTION: 1,
|
||||
ENCODING: TimeSeriesEncoding.UNCOMPRESSED,
|
||||
CHUNK_SIZE: 1,
|
||||
DUPLICATE_POLICY: TimeSeriesDuplicatePolicies.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']
|
||||
);
|
||||
});
|
||||
});
|
||||
|
@@ -6,8 +6,10 @@ import {
|
||||
TimeSeriesDuplicatePolicies,
|
||||
Labels,
|
||||
pushLabelsArgument,
|
||||
pushDuplicatePolicy
|
||||
pushDuplicatePolicy,
|
||||
pushIgnoreArgument
|
||||
} from '.';
|
||||
import { TsIgnoreOptions } from './ADD';
|
||||
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
@@ -17,6 +19,7 @@ interface CreateOptions {
|
||||
CHUNK_SIZE?: number;
|
||||
DUPLICATE_POLICY?: TimeSeriesDuplicatePolicies;
|
||||
LABELS?: Labels;
|
||||
IGNORE?: TsIgnoreOptions;
|
||||
}
|
||||
|
||||
export function transformArguments(key: string, options?: CreateOptions): Array<string> {
|
||||
@@ -32,6 +35,8 @@ export function transformArguments(key: string, options?: CreateOptions): Array<
|
||||
|
||||
pushLabelsArgument(args, options?.LABELS);
|
||||
|
||||
pushIgnoreArgument(args, options?.IGNORE);
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
|
@@ -127,6 +127,12 @@ export function transformTimestampArgument(timestamp: Timestamp): string {
|
||||
).toString();
|
||||
}
|
||||
|
||||
export function pushIgnoreArgument(args: RedisCommandArguments, ignore?: ADD.TsIgnoreOptions) {
|
||||
if (ignore !== undefined) {
|
||||
args.push('IGNORE', ignore.MAX_TIME_DIFF.toString(), ignore.MAX_VAL_DIFF.toString());
|
||||
}
|
||||
}
|
||||
|
||||
export function pushRetentionArgument(args: RedisCommandArguments, retention?: number): RedisCommandArguments {
|
||||
if (retention !== undefined) {
|
||||
args.push(
|
||||
|
Reference in New Issue
Block a user