1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00

Update doctest client with latest v4 release (#2844)

This commit is contained in:
Shaya Potter
2024-09-29 13:19:06 +03:00
committed by GitHub
parent fd7b10be6c
commit 49fdb79897
167 changed files with 8227 additions and 9599 deletions

View File

@@ -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']
);
});
});

View File

@@ -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;
}

View File

@@ -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']
);
});
});

View File

@@ -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;
}

View File

@@ -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']
);
});
});

View File

@@ -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;
}

View File

@@ -127,8 +127,14 @@ 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) {
if (retention !== undefined) {
args.push(
'RETENTION',
retention.toString()
@@ -144,7 +150,7 @@ export enum TimeSeriesEncoding {
}
export function pushEncodingArgument(args: RedisCommandArguments, encoding?: TimeSeriesEncoding): RedisCommandArguments {
if (encoding) {
if (encoding !== undefined) {
args.push(
'ENCODING',
encoding
@@ -155,7 +161,7 @@ export function pushEncodingArgument(args: RedisCommandArguments, encoding?: Tim
}
export function pushChunkSizeArgument(args: RedisCommandArguments, chunkSize?: number): RedisCommandArguments {
if (chunkSize) {
if (chunkSize !== undefined) {
args.push(
'CHUNK_SIZE',
chunkSize.toString()
@@ -166,7 +172,7 @@ export function pushChunkSizeArgument(args: RedisCommandArguments, chunkSize?: n
}
export function pushDuplicatePolicy(args: RedisCommandArguments, duplicatePolicy?: TimeSeriesDuplicatePolicies): RedisCommandArguments {
if (duplicatePolicy) {
if (duplicatePolicy !== undefined) {
args.push(
'DUPLICATE_POLICY',
duplicatePolicy