You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
new "transform arguments" API for better key and metadata extraction (#2733)
* Parser support with all commands * remove "dist" from all imports for consistency * address most of my review comments * small tweak to multi type mapping handling * tweak multi commands / fix addScript cases * nits * addressed all in person review comments * revert addCommand/addScript changes to multi-commands addCommand needs to be there for sendCommand like ability within a multi. If its there, it might as well be used by createCommand() et al, to avoid repeating code. addScript is there (even though only used once), but now made private to keep the logic for bookkeeping near each other.
This commit is contained in:
@@ -2,19 +2,20 @@ import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import ADD from './ADD';
|
||||
import { TIME_SERIES_ENCODING, TIME_SERIES_DUPLICATE_POLICIES } from '.';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('TS.ADD', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('without options', () => {
|
||||
assert.deepEqual(
|
||||
ADD.transformArguments('key', '*', 1),
|
||||
parseArgs(ADD, 'key', '*', 1),
|
||||
['TS.ADD', 'key', '*', '1']
|
||||
);
|
||||
});
|
||||
|
||||
it('with RETENTION', () => {
|
||||
assert.deepEqual(
|
||||
ADD.transformArguments('key', '*', 1, {
|
||||
parseArgs(ADD, 'key', '*', 1, {
|
||||
RETENTION: 1
|
||||
}),
|
||||
['TS.ADD', 'key', '*', '1', 'RETENTION', '1']
|
||||
@@ -23,7 +24,7 @@ describe('TS.ADD', () => {
|
||||
|
||||
it('with ENCODING', () => {
|
||||
assert.deepEqual(
|
||||
ADD.transformArguments('key', '*', 1, {
|
||||
parseArgs(ADD, 'key', '*', 1, {
|
||||
ENCODING: TIME_SERIES_ENCODING.UNCOMPRESSED
|
||||
}),
|
||||
['TS.ADD', 'key', '*', '1', 'ENCODING', 'UNCOMPRESSED']
|
||||
@@ -32,7 +33,7 @@ describe('TS.ADD', () => {
|
||||
|
||||
it('with CHUNK_SIZE', () => {
|
||||
assert.deepEqual(
|
||||
ADD.transformArguments('key', '*', 1, {
|
||||
parseArgs(ADD, 'key', '*', 1, {
|
||||
CHUNK_SIZE: 1
|
||||
}),
|
||||
['TS.ADD', 'key', '*', '1', 'CHUNK_SIZE', '1']
|
||||
@@ -41,7 +42,7 @@ describe('TS.ADD', () => {
|
||||
|
||||
it('with ON_DUPLICATE', () => {
|
||||
assert.deepEqual(
|
||||
ADD.transformArguments('key', '*', 1, {
|
||||
parseArgs(ADD, 'key', '*', 1, {
|
||||
ON_DUPLICATE: TIME_SERIES_DUPLICATE_POLICIES.BLOCK
|
||||
}),
|
||||
['TS.ADD', 'key', '*', '1', 'ON_DUPLICATE', 'BLOCK']
|
||||
@@ -50,7 +51,7 @@ describe('TS.ADD', () => {
|
||||
|
||||
it('with LABELS', () => {
|
||||
assert.deepEqual(
|
||||
ADD.transformArguments('key', '*', 1, {
|
||||
parseArgs(ADD, 'key', '*', 1, {
|
||||
LABELS: { label: 'value' }
|
||||
}),
|
||||
['TS.ADD', 'key', '*', '1', 'LABELS', 'label', 'value']
|
||||
@@ -59,7 +60,7 @@ describe('TS.ADD', () => {
|
||||
|
||||
it ('with IGNORE', () => {
|
||||
assert.deepEqual(
|
||||
ADD.transformArguments('key', '*', 1, {
|
||||
parseArgs(ADD, 'key', '*', 1, {
|
||||
IGNORE: {
|
||||
maxTimeDiff: 1,
|
||||
maxValDiff: 1
|
||||
@@ -71,7 +72,7 @@ describe('TS.ADD', () => {
|
||||
|
||||
it('with RETENTION, ENCODING, CHUNK_SIZE, ON_DUPLICATE, LABELS, IGNORE', () => {
|
||||
assert.deepEqual(
|
||||
ADD.transformArguments('key', '*', 1, {
|
||||
parseArgs(ADD, 'key', '*', 1, {
|
||||
RETENTION: 1,
|
||||
ENCODING: TIME_SERIES_ENCODING.UNCOMPRESSED,
|
||||
CHUNK_SIZE: 1,
|
||||
|
@@ -1,15 +1,16 @@
|
||||
import { RedisArgument, NumberReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||
import { CommandParser } from '@redis/client/lib/client/parser';
|
||||
import { RedisArgument, NumberReply, Command } from '@redis/client/lib/RESP/types';
|
||||
import {
|
||||
transformTimestampArgument,
|
||||
pushRetentionArgument,
|
||||
parseRetentionArgument,
|
||||
TimeSeriesEncoding,
|
||||
pushEncodingArgument,
|
||||
pushChunkSizeArgument,
|
||||
parseEncodingArgument,
|
||||
parseChunkSizeArgument,
|
||||
TimeSeriesDuplicatePolicies,
|
||||
Labels,
|
||||
pushLabelsArgument,
|
||||
parseLabelsArgument,
|
||||
Timestamp,
|
||||
pushIgnoreArgument
|
||||
parseIgnoreArgument
|
||||
} from '.';
|
||||
|
||||
export interface TsIgnoreOptions {
|
||||
@@ -27,36 +28,31 @@ export interface TsAddOptions {
|
||||
}
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: false,
|
||||
transformArguments(
|
||||
parseCommand(
|
||||
parser: CommandParser,
|
||||
key: RedisArgument,
|
||||
timestamp: Timestamp,
|
||||
value: number,
|
||||
options?: TsAddOptions
|
||||
) {
|
||||
const args = [
|
||||
'TS.ADD',
|
||||
key,
|
||||
transformTimestampArgument(timestamp),
|
||||
value.toString()
|
||||
];
|
||||
parser.push('TS.ADD');
|
||||
parser.pushKey(key);
|
||||
parser.push(transformTimestampArgument(timestamp), value.toString());
|
||||
|
||||
pushRetentionArgument(args, options?.RETENTION);
|
||||
parseRetentionArgument(parser, options?.RETENTION);
|
||||
|
||||
pushEncodingArgument(args, options?.ENCODING);
|
||||
parseEncodingArgument(parser, options?.ENCODING);
|
||||
|
||||
pushChunkSizeArgument(args, options?.CHUNK_SIZE);
|
||||
parseChunkSizeArgument(parser, options?.CHUNK_SIZE);
|
||||
|
||||
if (options?.ON_DUPLICATE) {
|
||||
args.push('ON_DUPLICATE', options.ON_DUPLICATE);
|
||||
parser.push('ON_DUPLICATE', options.ON_DUPLICATE);
|
||||
}
|
||||
|
||||
pushLabelsArgument(args, options?.LABELS);
|
||||
parseLabelsArgument(parser, options?.LABELS);
|
||||
|
||||
pushIgnoreArgument(args, options?.IGNORE);
|
||||
|
||||
return args;
|
||||
parseIgnoreArgument(parser, options?.IGNORE);
|
||||
},
|
||||
transformReply: undefined as unknown as () => NumberReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -2,19 +2,20 @@ import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import ALTER from './ALTER';
|
||||
import { TIME_SERIES_DUPLICATE_POLICIES } from '.';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('TS.ALTER', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('without options', () => {
|
||||
assert.deepEqual(
|
||||
ALTER.transformArguments('key'),
|
||||
parseArgs(ALTER, 'key'),
|
||||
['TS.ALTER', 'key']
|
||||
);
|
||||
});
|
||||
|
||||
it('with RETENTION', () => {
|
||||
assert.deepEqual(
|
||||
ALTER.transformArguments('key', {
|
||||
parseArgs(ALTER, 'key', {
|
||||
RETENTION: 1
|
||||
}),
|
||||
['TS.ALTER', 'key', 'RETENTION', '1']
|
||||
@@ -23,7 +24,7 @@ describe('TS.ALTER', () => {
|
||||
|
||||
it('with CHUNK_SIZE', () => {
|
||||
assert.deepEqual(
|
||||
ALTER.transformArguments('key', {
|
||||
parseArgs(ALTER, 'key', {
|
||||
CHUNK_SIZE: 1
|
||||
}),
|
||||
['TS.ALTER', 'key', 'CHUNK_SIZE', '1']
|
||||
@@ -32,7 +33,7 @@ describe('TS.ALTER', () => {
|
||||
|
||||
it('with DUPLICATE_POLICY', () => {
|
||||
assert.deepEqual(
|
||||
ALTER.transformArguments('key', {
|
||||
parseArgs(ALTER, 'key', {
|
||||
DUPLICATE_POLICY: TIME_SERIES_DUPLICATE_POLICIES.BLOCK
|
||||
}),
|
||||
['TS.ALTER', 'key', 'DUPLICATE_POLICY', 'BLOCK']
|
||||
@@ -41,7 +42,7 @@ describe('TS.ALTER', () => {
|
||||
|
||||
it('with LABELS', () => {
|
||||
assert.deepEqual(
|
||||
ALTER.transformArguments('key', {
|
||||
parseArgs(ALTER, 'key', {
|
||||
LABELS: { label: 'value' }
|
||||
}),
|
||||
['TS.ALTER', 'key', 'LABELS', 'label', 'value']
|
||||
@@ -50,7 +51,7 @@ describe('TS.ALTER', () => {
|
||||
|
||||
it('with IGNORE with MAX_TIME_DIFF', () => {
|
||||
assert.deepEqual(
|
||||
ALTER.transformArguments('key', {
|
||||
parseArgs(ALTER, 'key', {
|
||||
IGNORE: {
|
||||
maxTimeDiff: 1,
|
||||
maxValDiff: 1
|
||||
@@ -62,7 +63,7 @@ describe('TS.ALTER', () => {
|
||||
|
||||
it('with RETENTION, CHUNK_SIZE, DUPLICATE_POLICY, LABELS, IGNORE', () => {
|
||||
assert.deepEqual(
|
||||
ALTER.transformArguments('key', {
|
||||
parseArgs(ALTER, 'key', {
|
||||
RETENTION: 1,
|
||||
CHUNK_SIZE: 1,
|
||||
DUPLICATE_POLICY: TIME_SERIES_DUPLICATE_POLICIES.BLOCK,
|
||||
|
@@ -1,26 +1,25 @@
|
||||
import { RedisArgument, SimpleStringReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||
import { CommandParser } from '@redis/client/lib/client/parser';
|
||||
import { RedisArgument, SimpleStringReply, Command } from '@redis/client/lib/RESP/types';
|
||||
import { TsCreateOptions } from './CREATE';
|
||||
import { pushRetentionArgument, pushChunkSizeArgument, pushDuplicatePolicy, pushLabelsArgument, pushIgnoreArgument } from '.';
|
||||
import { parseRetentionArgument, parseChunkSizeArgument, parseDuplicatePolicy, parseLabelsArgument, parseIgnoreArgument } from '.';
|
||||
|
||||
export type TsAlterOptions = Pick<TsCreateOptions, 'RETENTION' | 'CHUNK_SIZE' | 'DUPLICATE_POLICY' | 'LABELS' | 'IGNORE'>;
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: false,
|
||||
transformArguments(key: RedisArgument, options?: TsAlterOptions) {
|
||||
const args = ['TS.ALTER', key];
|
||||
parseCommand(parser: CommandParser, key: RedisArgument, options?: TsAlterOptions) {
|
||||
parser.push('TS.ALTER');
|
||||
parser.pushKey(key);
|
||||
|
||||
pushRetentionArgument(args, options?.RETENTION);
|
||||
parseRetentionArgument(parser, options?.RETENTION);
|
||||
|
||||
pushChunkSizeArgument(args, options?.CHUNK_SIZE);
|
||||
parseChunkSizeArgument(parser, options?.CHUNK_SIZE);
|
||||
|
||||
pushDuplicatePolicy(args, options?.DUPLICATE_POLICY);
|
||||
parseDuplicatePolicy(parser, options?.DUPLICATE_POLICY);
|
||||
|
||||
pushLabelsArgument(args, options?.LABELS);
|
||||
parseLabelsArgument(parser, options?.LABELS);
|
||||
|
||||
pushIgnoreArgument(args, options?.IGNORE);
|
||||
|
||||
return args;
|
||||
parseIgnoreArgument(parser, options?.IGNORE);
|
||||
},
|
||||
transformReply: undefined as unknown as () => SimpleStringReply<'OK'>
|
||||
transformReply: undefined as unknown as () => SimpleStringReply<'OK'>
|
||||
} as const satisfies Command;
|
||||
|
@@ -2,19 +2,20 @@ import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import CREATE from './CREATE';
|
||||
import { TIME_SERIES_ENCODING, TIME_SERIES_DUPLICATE_POLICIES } from '.';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('TS.CREATE', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('without options', () => {
|
||||
assert.deepEqual(
|
||||
CREATE.transformArguments('key'),
|
||||
parseArgs(CREATE, 'key'),
|
||||
['TS.CREATE', 'key']
|
||||
);
|
||||
});
|
||||
|
||||
it('with RETENTION', () => {
|
||||
assert.deepEqual(
|
||||
CREATE.transformArguments('key', {
|
||||
parseArgs(CREATE, 'key', {
|
||||
RETENTION: 1
|
||||
}),
|
||||
['TS.CREATE', 'key', 'RETENTION', '1']
|
||||
@@ -23,7 +24,7 @@ describe('TS.CREATE', () => {
|
||||
|
||||
it('with ENCODING', () => {
|
||||
assert.deepEqual(
|
||||
CREATE.transformArguments('key', {
|
||||
parseArgs(CREATE, 'key', {
|
||||
ENCODING: TIME_SERIES_ENCODING.UNCOMPRESSED
|
||||
}),
|
||||
['TS.CREATE', 'key', 'ENCODING', 'UNCOMPRESSED']
|
||||
@@ -32,7 +33,7 @@ describe('TS.CREATE', () => {
|
||||
|
||||
it('with CHUNK_SIZE', () => {
|
||||
assert.deepEqual(
|
||||
CREATE.transformArguments('key', {
|
||||
parseArgs(CREATE, 'key', {
|
||||
CHUNK_SIZE: 1
|
||||
}),
|
||||
['TS.CREATE', 'key', 'CHUNK_SIZE', '1']
|
||||
@@ -41,7 +42,7 @@ describe('TS.CREATE', () => {
|
||||
|
||||
it('with DUPLICATE_POLICY', () => {
|
||||
assert.deepEqual(
|
||||
CREATE.transformArguments('key', {
|
||||
parseArgs(CREATE, 'key', {
|
||||
DUPLICATE_POLICY: TIME_SERIES_DUPLICATE_POLICIES.BLOCK
|
||||
}),
|
||||
['TS.CREATE', 'key', 'DUPLICATE_POLICY', 'BLOCK']
|
||||
@@ -50,7 +51,7 @@ describe('TS.CREATE', () => {
|
||||
|
||||
it('with LABELS', () => {
|
||||
assert.deepEqual(
|
||||
CREATE.transformArguments('key', {
|
||||
parseArgs(CREATE, 'key', {
|
||||
LABELS: { label: 'value' }
|
||||
}),
|
||||
['TS.CREATE', 'key', 'LABELS', 'label', 'value']
|
||||
@@ -59,7 +60,7 @@ describe('TS.CREATE', () => {
|
||||
|
||||
it('with IGNORE with MAX_TIME_DIFF', () => {
|
||||
assert.deepEqual(
|
||||
CREATE.transformArguments('key', {
|
||||
parseArgs(CREATE, 'key', {
|
||||
IGNORE: {
|
||||
maxTimeDiff: 1,
|
||||
maxValDiff: 1
|
||||
@@ -71,7 +72,7 @@ describe('TS.CREATE', () => {
|
||||
|
||||
it('with RETENTION, ENCODING, CHUNK_SIZE, DUPLICATE_POLICY, LABELS, IGNORE', () => {
|
||||
assert.deepEqual(
|
||||
CREATE.transformArguments('key', {
|
||||
parseArgs(CREATE, 'key', {
|
||||
RETENTION: 1,
|
||||
ENCODING: TIME_SERIES_ENCODING.UNCOMPRESSED,
|
||||
CHUNK_SIZE: 1,
|
||||
|
@@ -1,14 +1,15 @@
|
||||
import { RedisArgument, SimpleStringReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||
import { CommandParser } from '@redis/client/lib/client/parser';
|
||||
import { RedisArgument, SimpleStringReply, Command } from '@redis/client/lib/RESP/types';
|
||||
import {
|
||||
pushRetentionArgument,
|
||||
parseRetentionArgument,
|
||||
TimeSeriesEncoding,
|
||||
pushEncodingArgument,
|
||||
pushChunkSizeArgument,
|
||||
parseEncodingArgument,
|
||||
parseChunkSizeArgument,
|
||||
TimeSeriesDuplicatePolicies,
|
||||
pushDuplicatePolicy,
|
||||
parseDuplicatePolicy,
|
||||
Labels,
|
||||
pushLabelsArgument,
|
||||
pushIgnoreArgument
|
||||
parseLabelsArgument,
|
||||
parseIgnoreArgument
|
||||
} from '.';
|
||||
import { TsIgnoreOptions } from './ADD';
|
||||
|
||||
@@ -22,24 +23,22 @@ export interface TsCreateOptions {
|
||||
}
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: false,
|
||||
transformArguments(key: RedisArgument, options?: TsCreateOptions) {
|
||||
const args = ['TS.CREATE', key];
|
||||
parseCommand(parser: CommandParser, key: RedisArgument, options?: TsCreateOptions) {
|
||||
parser.push('TS.CREATE');
|
||||
parser.pushKey(key);
|
||||
|
||||
pushRetentionArgument(args, options?.RETENTION);
|
||||
parseRetentionArgument(parser, options?.RETENTION);
|
||||
|
||||
pushEncodingArgument(args, options?.ENCODING);
|
||||
parseEncodingArgument(parser, options?.ENCODING);
|
||||
|
||||
pushChunkSizeArgument(args, options?.CHUNK_SIZE);
|
||||
parseChunkSizeArgument(parser, options?.CHUNK_SIZE);
|
||||
|
||||
pushDuplicatePolicy(args, options?.DUPLICATE_POLICY);
|
||||
parseDuplicatePolicy(parser, options?.DUPLICATE_POLICY);
|
||||
|
||||
pushLabelsArgument(args, options?.LABELS);
|
||||
parseLabelsArgument(parser, options?.LABELS);
|
||||
|
||||
pushIgnoreArgument(args, options?.IGNORE);
|
||||
|
||||
return args;
|
||||
parseIgnoreArgument(parser, options?.IGNORE);
|
||||
},
|
||||
transformReply: undefined as unknown as () => SimpleStringReply<'OK'>
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,19 +1,20 @@
|
||||
import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import CREATERULE, { TIME_SERIES_AGGREGATION_TYPE } from './CREATERULE';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('TS.CREATERULE', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('without options', () => {
|
||||
assert.deepEqual(
|
||||
CREATERULE.transformArguments('source', 'destination', TIME_SERIES_AGGREGATION_TYPE.AVG, 1),
|
||||
parseArgs(CREATERULE, 'source', 'destination', TIME_SERIES_AGGREGATION_TYPE.AVG, 1),
|
||||
['TS.CREATERULE', 'source', 'destination', 'AGGREGATION', 'AVG', '1']
|
||||
);
|
||||
});
|
||||
|
||||
it('with alignTimestamp', () => {
|
||||
assert.deepEqual(
|
||||
CREATERULE.transformArguments('source', 'destination', TIME_SERIES_AGGREGATION_TYPE.AVG, 1, 1),
|
||||
parseArgs(CREATERULE, 'source', 'destination', TIME_SERIES_AGGREGATION_TYPE.AVG, 1, 1),
|
||||
['TS.CREATERULE', 'source', 'destination', 'AGGREGATION', 'AVG', '1', '1']
|
||||
);
|
||||
});
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import { RedisArgument, SimpleStringReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||
import { CommandParser } from '@redis/client/lib/client/parser';
|
||||
import { RedisArgument, SimpleStringReply, Command } from '@redis/client/lib/RESP/types';
|
||||
|
||||
export const TIME_SERIES_AGGREGATION_TYPE = {
|
||||
AVG: 'AVG',
|
||||
@@ -19,29 +20,22 @@ export const TIME_SERIES_AGGREGATION_TYPE = {
|
||||
export type TimeSeriesAggregationType = typeof TIME_SERIES_AGGREGATION_TYPE[keyof typeof TIME_SERIES_AGGREGATION_TYPE];
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: false,
|
||||
transformArguments(
|
||||
parseCommand(
|
||||
parser: CommandParser,
|
||||
sourceKey: RedisArgument,
|
||||
destinationKey: RedisArgument,
|
||||
aggregationType: TimeSeriesAggregationType,
|
||||
bucketDuration: number,
|
||||
alignTimestamp?: number
|
||||
) {
|
||||
const args = [
|
||||
'TS.CREATERULE',
|
||||
sourceKey,
|
||||
destinationKey,
|
||||
'AGGREGATION',
|
||||
aggregationType,
|
||||
bucketDuration.toString()
|
||||
];
|
||||
parser.push('TS.CREATERULE');
|
||||
parser.pushKeys([sourceKey, destinationKey]);
|
||||
parser.push('AGGREGATION', aggregationType, bucketDuration.toString());
|
||||
|
||||
if (alignTimestamp !== undefined) {
|
||||
args.push(alignTimestamp.toString());
|
||||
parser.push(alignTimestamp.toString());
|
||||
}
|
||||
|
||||
return args;
|
||||
},
|
||||
transformReply: undefined as unknown as () => SimpleStringReply<'OK'>
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,19 +1,20 @@
|
||||
import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import DECRBY from './DECRBY';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('TS.DECRBY', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('without options', () => {
|
||||
assert.deepEqual(
|
||||
DECRBY.transformArguments('key', 1),
|
||||
parseArgs(DECRBY, 'key', 1),
|
||||
['TS.DECRBY', 'key', '1']
|
||||
);
|
||||
});
|
||||
|
||||
it('with TIMESTAMP', () => {
|
||||
assert.deepEqual(
|
||||
DECRBY.transformArguments('key', 1, {
|
||||
parseArgs(DECRBY, 'key', 1, {
|
||||
TIMESTAMP: '*'
|
||||
}),
|
||||
['TS.DECRBY', 'key', '1', 'TIMESTAMP', '*']
|
||||
@@ -22,7 +23,7 @@ describe('TS.DECRBY', () => {
|
||||
|
||||
it('with RETENTION', () => {
|
||||
assert.deepEqual(
|
||||
DECRBY.transformArguments('key', 1, {
|
||||
parseArgs(DECRBY, 'key', 1, {
|
||||
RETENTION: 1
|
||||
}),
|
||||
['TS.DECRBY', 'key', '1', 'RETENTION', '1']
|
||||
@@ -31,7 +32,7 @@ describe('TS.DECRBY', () => {
|
||||
|
||||
it('with UNCOMPRESSED', () => {
|
||||
assert.deepEqual(
|
||||
DECRBY.transformArguments('key', 1, {
|
||||
parseArgs(DECRBY, 'key', 1, {
|
||||
UNCOMPRESSED: true
|
||||
}),
|
||||
['TS.DECRBY', 'key', '1', 'UNCOMPRESSED']
|
||||
@@ -40,7 +41,7 @@ describe('TS.DECRBY', () => {
|
||||
|
||||
it('with CHUNK_SIZE', () => {
|
||||
assert.deepEqual(
|
||||
DECRBY.transformArguments('key', 1, {
|
||||
parseArgs(DECRBY, 'key', 1, {
|
||||
CHUNK_SIZE: 100
|
||||
}),
|
||||
['TS.DECRBY', 'key', '1', 'CHUNK_SIZE', '100']
|
||||
@@ -49,7 +50,7 @@ describe('TS.DECRBY', () => {
|
||||
|
||||
it('with LABELS', () => {
|
||||
assert.deepEqual(
|
||||
DECRBY.transformArguments('key', 1, {
|
||||
parseArgs(DECRBY, 'key', 1, {
|
||||
LABELS: { label: 'value' }
|
||||
}),
|
||||
['TS.DECRBY', 'key', '1', 'LABELS', 'label', 'value']
|
||||
@@ -58,7 +59,7 @@ describe('TS.DECRBY', () => {
|
||||
|
||||
it ('with IGNORE', () => {
|
||||
assert.deepEqual(
|
||||
DECRBY.transformArguments('key', 1, {
|
||||
parseArgs(DECRBY, 'key', 1, {
|
||||
IGNORE: {
|
||||
maxTimeDiff: 1,
|
||||
maxValDiff: 1
|
||||
@@ -70,7 +71,7 @@ describe('TS.DECRBY', () => {
|
||||
|
||||
it('with TIMESTAMP, RETENTION, UNCOMPRESSED, CHUNK_SIZE and LABELS', () => {
|
||||
assert.deepEqual(
|
||||
DECRBY.transformArguments('key', 1, {
|
||||
parseArgs(DECRBY, 'key', 1, {
|
||||
TIMESTAMP: '*',
|
||||
RETENTION: 1,
|
||||
UNCOMPRESSED: true,
|
||||
|
@@ -1,9 +1,13 @@
|
||||
import { Command } from '@redis/client/dist/lib/RESP/types';
|
||||
import INCRBY, { transformIncrByArguments } from './INCRBY';
|
||||
import { Command } from '@redis/client/lib/RESP/types';
|
||||
import INCRBY, { parseIncrByArguments } from './INCRBY';
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: INCRBY.FIRST_KEY_INDEX,
|
||||
IS_READ_ONLY: INCRBY.IS_READ_ONLY,
|
||||
transformArguments: transformIncrByArguments.bind(undefined, 'TS.DECRBY'),
|
||||
parseCommand(...args: Parameters<typeof parseIncrByArguments>) {
|
||||
const parser = args[0];
|
||||
|
||||
parser.push('TS.DECRBY');
|
||||
parseIncrByArguments(...args);
|
||||
},
|
||||
transformReply: INCRBY.transformReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,11 +1,12 @@
|
||||
import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import DEL from './DEL';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('TS.DEL', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
DEL.transformArguments('key', '-', '+'),
|
||||
parseArgs(DEL, 'key', '-', '+'),
|
||||
['TS.DEL', 'key', '-', '+']
|
||||
);
|
||||
});
|
||||
|
@@ -1,16 +1,13 @@
|
||||
import { CommandParser } from '@redis/client/lib/client/parser';
|
||||
import { Timestamp, transformTimestampArgument } from '.';
|
||||
import { RedisArgument, NumberReply, Command, } from '@redis/client/dist/lib/RESP/types';
|
||||
import { RedisArgument, NumberReply, Command, } from '@redis/client/lib/RESP/types';
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: false,
|
||||
transformArguments(key: RedisArgument, fromTimestamp: Timestamp, toTimestamp: Timestamp) {
|
||||
return [
|
||||
'TS.DEL',
|
||||
key,
|
||||
transformTimestampArgument(fromTimestamp),
|
||||
transformTimestampArgument(toTimestamp)
|
||||
];
|
||||
parseCommand(parser: CommandParser, key: RedisArgument, fromTimestamp: Timestamp, toTimestamp: Timestamp) {
|
||||
parser.push('TS.DEL');
|
||||
parser.pushKey(key);
|
||||
parser.push(transformTimestampArgument(fromTimestamp), transformTimestampArgument(toTimestamp));
|
||||
},
|
||||
transformReply: undefined as unknown as () => NumberReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -2,11 +2,12 @@ import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import DELETERULE from './DELETERULE';
|
||||
import { TIME_SERIES_AGGREGATION_TYPE } from './CREATERULE';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('TS.DELETERULE', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
DELETERULE.transformArguments('source', 'destination'),
|
||||
parseArgs(DELETERULE, 'source', 'destination'),
|
||||
['TS.DELETERULE', 'source', 'destination']
|
||||
);
|
||||
});
|
||||
|
@@ -1,14 +1,11 @@
|
||||
import { RedisArgument, SimpleStringReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||
import { CommandParser } from '@redis/client/lib/client/parser';
|
||||
import { RedisArgument, SimpleStringReply, Command } from '@redis/client/lib/RESP/types';
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: false,
|
||||
transformArguments(sourceKey: RedisArgument, destinationKey: RedisArgument) {
|
||||
return [
|
||||
'TS.DELETERULE',
|
||||
sourceKey,
|
||||
destinationKey
|
||||
];
|
||||
parseCommand(parser: CommandParser, sourceKey: RedisArgument, destinationKey: RedisArgument) {
|
||||
parser.push('TS.DELETERULE');
|
||||
parser.pushKeys([sourceKey, destinationKey]);
|
||||
},
|
||||
transformReply: undefined as unknown as () => SimpleStringReply<'OK'>
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,19 +1,20 @@
|
||||
import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import GET from './GET';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('TS.GET', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('without options', () => {
|
||||
assert.deepEqual(
|
||||
GET.transformArguments('key'),
|
||||
parseArgs(GET, 'key'),
|
||||
['TS.GET', 'key']
|
||||
);
|
||||
});
|
||||
|
||||
it('with LATEST', () => {
|
||||
assert.deepEqual(
|
||||
GET.transformArguments('key', {
|
||||
parseArgs(GET, 'key', {
|
||||
LATEST: true
|
||||
}),
|
||||
['TS.GET', 'key', 'LATEST']
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import { RedisArgument, TuplesReply, NumberReply, DoubleReply, UnwrapReply, Resp2Reply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||
import { CommandParser } from '@redis/client/lib/client/parser';
|
||||
import { RedisArgument, TuplesReply, NumberReply, DoubleReply, UnwrapReply, Resp2Reply, Command } from '@redis/client/lib/RESP/types';
|
||||
|
||||
export interface TsGetOptions {
|
||||
LATEST?: boolean;
|
||||
@@ -7,16 +8,14 @@ export interface TsGetOptions {
|
||||
export type TsGetReply = TuplesReply<[]> | TuplesReply<[NumberReply, DoubleReply]>;
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(key: RedisArgument, options?: TsGetOptions) {
|
||||
const args = ['TS.GET', key];
|
||||
parseCommand(parser: CommandParser, key: RedisArgument, options?: TsGetOptions) {
|
||||
parser.push('TS.GET');
|
||||
parser.pushKey(key);
|
||||
|
||||
if (options?.LATEST) {
|
||||
args.push('LATEST');
|
||||
parser.push('LATEST');
|
||||
}
|
||||
|
||||
return args;
|
||||
},
|
||||
transformReply: {
|
||||
2(reply: UnwrapReply<Resp2Reply<TsGetReply>>) {
|
||||
|
@@ -1,19 +1,20 @@
|
||||
import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import INCRBY from './INCRBY';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('TS.INCRBY', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('without options', () => {
|
||||
assert.deepEqual(
|
||||
INCRBY.transformArguments('key', 1),
|
||||
parseArgs(INCRBY, 'key', 1),
|
||||
['TS.INCRBY', 'key', '1']
|
||||
);
|
||||
});
|
||||
|
||||
it('with TIMESTAMP', () => {
|
||||
assert.deepEqual(
|
||||
INCRBY.transformArguments('key', 1, {
|
||||
parseArgs(INCRBY, 'key', 1, {
|
||||
TIMESTAMP: '*'
|
||||
}),
|
||||
['TS.INCRBY', 'key', '1', 'TIMESTAMP', '*']
|
||||
@@ -22,7 +23,7 @@ describe('TS.INCRBY', () => {
|
||||
|
||||
it('with RETENTION', () => {
|
||||
assert.deepEqual(
|
||||
INCRBY.transformArguments('key', 1, {
|
||||
parseArgs(INCRBY, 'key', 1, {
|
||||
RETENTION: 1
|
||||
}),
|
||||
['TS.INCRBY', 'key', '1', 'RETENTION', '1']
|
||||
@@ -31,7 +32,7 @@ describe('TS.INCRBY', () => {
|
||||
|
||||
it('with UNCOMPRESSED', () => {
|
||||
assert.deepEqual(
|
||||
INCRBY.transformArguments('key', 1, {
|
||||
parseArgs(INCRBY, 'key', 1, {
|
||||
UNCOMPRESSED: true
|
||||
}),
|
||||
['TS.INCRBY', 'key', '1', 'UNCOMPRESSED']
|
||||
@@ -40,7 +41,7 @@ describe('TS.INCRBY', () => {
|
||||
|
||||
it('without UNCOMPRESSED', () => {
|
||||
assert.deepEqual(
|
||||
INCRBY.transformArguments('key', 1, {
|
||||
parseArgs(INCRBY, 'key', 1, {
|
||||
UNCOMPRESSED: false
|
||||
}),
|
||||
['TS.INCRBY', 'key', '1']
|
||||
@@ -49,7 +50,7 @@ describe('TS.INCRBY', () => {
|
||||
|
||||
it('with CHUNK_SIZE', () => {
|
||||
assert.deepEqual(
|
||||
INCRBY.transformArguments('key', 1, {
|
||||
parseArgs(INCRBY, 'key', 1, {
|
||||
CHUNK_SIZE: 1
|
||||
}),
|
||||
['TS.INCRBY', 'key', '1', 'CHUNK_SIZE', '1']
|
||||
@@ -58,7 +59,7 @@ describe('TS.INCRBY', () => {
|
||||
|
||||
it('with LABELS', () => {
|
||||
assert.deepEqual(
|
||||
INCRBY.transformArguments('key', 1, {
|
||||
parseArgs(INCRBY, 'key', 1, {
|
||||
LABELS: { label: 'value' }
|
||||
}),
|
||||
['TS.INCRBY', 'key', '1', 'LABELS', 'label', 'value']
|
||||
@@ -67,7 +68,7 @@ describe('TS.INCRBY', () => {
|
||||
|
||||
it ('with IGNORE', () => {
|
||||
assert.deepEqual(
|
||||
INCRBY.transformArguments('key', 1, {
|
||||
parseArgs(INCRBY, 'key', 1, {
|
||||
IGNORE: {
|
||||
maxTimeDiff: 1,
|
||||
maxValDiff: 1
|
||||
@@ -79,7 +80,7 @@ describe('TS.INCRBY', () => {
|
||||
|
||||
it('with TIMESTAMP, RETENTION, UNCOMPRESSED, CHUNK_SIZE and LABELS', () => {
|
||||
assert.deepEqual(
|
||||
INCRBY.transformArguments('key', 1, {
|
||||
parseArgs(INCRBY, 'key', 1, {
|
||||
TIMESTAMP: '*',
|
||||
RETENTION: 1,
|
||||
UNCOMPRESSED: true,
|
||||
|
@@ -1,5 +1,6 @@
|
||||
import { RedisArgument, NumberReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||
import { Timestamp, transformTimestampArgument, pushRetentionArgument, pushChunkSizeArgument, Labels, pushLabelsArgument, pushIgnoreArgument } from '.';
|
||||
import { CommandParser } from '@redis/client/lib/client/parser';
|
||||
import { RedisArgument, NumberReply, Command } from '@redis/client/lib/RESP/types';
|
||||
import { Timestamp, transformTimestampArgument, parseRetentionArgument, parseChunkSizeArgument, Labels, parseLabelsArgument, parseIgnoreArgument } from '.';
|
||||
import { TsIgnoreOptions } from './ADD';
|
||||
|
||||
export interface TsIncrByOptions {
|
||||
@@ -11,40 +12,39 @@ export interface TsIncrByOptions {
|
||||
IGNORE?: TsIgnoreOptions;
|
||||
}
|
||||
|
||||
export function transformIncrByArguments(
|
||||
command: RedisArgument,
|
||||
export function parseIncrByArguments(
|
||||
parser: CommandParser,
|
||||
key: RedisArgument,
|
||||
value: number,
|
||||
options?: TsIncrByOptions
|
||||
) {
|
||||
const args = [
|
||||
command,
|
||||
key,
|
||||
value.toString()
|
||||
];
|
||||
parser.pushKey(key);
|
||||
parser.push(value.toString());
|
||||
|
||||
if (options?.TIMESTAMP !== undefined && options?.TIMESTAMP !== null) {
|
||||
args.push('TIMESTAMP', transformTimestampArgument(options.TIMESTAMP));
|
||||
parser.push('TIMESTAMP', transformTimestampArgument(options.TIMESTAMP));
|
||||
}
|
||||
|
||||
pushRetentionArgument(args, options?.RETENTION);
|
||||
parseRetentionArgument(parser, options?.RETENTION);
|
||||
|
||||
if (options?.UNCOMPRESSED) {
|
||||
args.push('UNCOMPRESSED');
|
||||
parser.push('UNCOMPRESSED');
|
||||
}
|
||||
|
||||
pushChunkSizeArgument(args, options?.CHUNK_SIZE);
|
||||
parseChunkSizeArgument(parser, options?.CHUNK_SIZE);
|
||||
|
||||
pushLabelsArgument(args, options?.LABELS);
|
||||
parseLabelsArgument(parser, options?.LABELS);
|
||||
|
||||
pushIgnoreArgument(args, options?.IGNORE);
|
||||
|
||||
return args;
|
||||
parseIgnoreArgument(parser, options?.IGNORE);
|
||||
}
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: false,
|
||||
transformArguments: transformIncrByArguments.bind(undefined, 'TS.INCRBY'),
|
||||
parseCommand(...args: Parameters<typeof parseIncrByArguments>) {
|
||||
const parser = args[0];
|
||||
|
||||
parser.push('TS.INCRBY');
|
||||
parseIncrByArguments(...args);
|
||||
},
|
||||
transformReply: undefined as unknown as () => NumberReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -3,11 +3,12 @@ import { TIME_SERIES_DUPLICATE_POLICIES } from '.';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import INFO, { InfoReply } from './INFO';
|
||||
import { TIME_SERIES_AGGREGATION_TYPE } from './CREATERULE';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('TS.INFO', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
INFO.transformArguments('key'),
|
||||
parseArgs(INFO, 'key'),
|
||||
['TS.INFO', 'key']
|
||||
);
|
||||
});
|
||||
|
@@ -1,3 +1,4 @@
|
||||
import { CommandParser } from '@redis/client/lib/client/parser';
|
||||
import { ArrayReply, BlobStringReply, Command, DoubleReply, NumberReply, ReplyUnion, SimpleStringReply, TypeMapping } from "@redis/client/lib/RESP/types";
|
||||
import { TimeSeriesDuplicatePolicies } from ".";
|
||||
import { TimeSeriesAggregationType } from "./CREATERULE";
|
||||
@@ -71,10 +72,10 @@ export interface InfoReply {
|
||||
}
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(key: string) {
|
||||
return ['TS.INFO', key];
|
||||
parseCommand(parser: CommandParser, key: string) {
|
||||
parser.push('TS.INFO');
|
||||
parser.pushKey(key);
|
||||
},
|
||||
transformReply: {
|
||||
2: (reply: InfoRawReply, _, typeMapping?: TypeMapping): InfoReply => {
|
||||
@@ -125,4 +126,4 @@ export default {
|
||||
3: undefined as unknown as () => ReplyUnion
|
||||
},
|
||||
unstableResp3: true
|
||||
} as const satisfies Command;
|
||||
} as const satisfies Command;
|
||||
|
@@ -4,11 +4,12 @@ import testUtils, { GLOBAL } from '../test-utils';
|
||||
import { assertInfo } from './INFO.spec';
|
||||
import INFO_DEBUG from './INFO_DEBUG';
|
||||
import { TIME_SERIES_AGGREGATION_TYPE } from './CREATERULE';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('TS.INFO_DEBUG', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
INFO_DEBUG.transformArguments('key'),
|
||||
parseArgs(INFO_DEBUG, 'key'),
|
||||
['TS.INFO', 'key', 'DEBUG']
|
||||
);
|
||||
});
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import { BlobStringReply, Command, NumberReply, SimpleStringReply, TypeMapping } from "@redis/client/lib/RESP/types";
|
||||
import { CommandParser } from '@redis/client/lib/client/parser';
|
||||
import { BlobStringReply, Command, NumberReply, SimpleStringReply, TypeMapping, ReplyUnion } from "@redis/client/lib/RESP/types";
|
||||
import INFO, { InfoRawReply, InfoRawReplyTypes, InfoReply } from "./INFO";
|
||||
import { ReplyUnion } from '@redis/client/lib/RESP/types';
|
||||
|
||||
type chunkType = Array<[
|
||||
'startTimestamp',
|
||||
@@ -37,12 +37,10 @@ export interface InfoDebugReply extends InfoReply {
|
||||
}
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: INFO.FIRST_KEY_INDEX,
|
||||
IS_READ_ONLY: INFO.IS_READ_ONLY,
|
||||
transformArguments(key: string) {
|
||||
const args = INFO.transformArguments(key);
|
||||
args.push('DEBUG');
|
||||
return args;
|
||||
parseCommand(parser: CommandParser, key: string) {
|
||||
INFO.parseCommand(parser, key);
|
||||
parser.push('DEBUG');
|
||||
},
|
||||
transformReply: {
|
||||
2: (reply: InfoDebugRawReply, _, typeMapping?: TypeMapping): InfoDebugReply => {
|
||||
@@ -76,4 +74,4 @@ export default {
|
||||
3: undefined as unknown as () => ReplyUnion
|
||||
},
|
||||
unstableResp3: true
|
||||
} as const satisfies Command;
|
||||
} as const satisfies Command;
|
||||
|
@@ -2,11 +2,12 @@ import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import MADD from './MADD';
|
||||
import { SimpleError } from '@redis/client/lib/errors';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('TS.MADD', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
MADD.transformArguments([{
|
||||
parseArgs(MADD, [{
|
||||
key: '1',
|
||||
timestamp: 0,
|
||||
value: 0
|
||||
|
@@ -1,5 +1,6 @@
|
||||
import { CommandParser } from '@redis/client/lib/client/parser';
|
||||
import { Timestamp, transformTimestampArgument } from '.';
|
||||
import { ArrayReply, NumberReply, SimpleErrorReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||
import { ArrayReply, NumberReply, SimpleErrorReply, Command } from '@redis/client/lib/RESP/types';
|
||||
|
||||
export interface TsMAddSample {
|
||||
key: string;
|
||||
@@ -8,20 +9,14 @@ export interface TsMAddSample {
|
||||
}
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: false,
|
||||
transformArguments(toAdd: Array<TsMAddSample>) {
|
||||
const args = ['TS.MADD'];
|
||||
parseCommand(parser: CommandParser, toAdd: Array<TsMAddSample>) {
|
||||
parser.push('TS.MADD');
|
||||
|
||||
for (const { key, timestamp, value } of toAdd) {
|
||||
args.push(
|
||||
key,
|
||||
transformTimestampArgument(timestamp),
|
||||
value.toString()
|
||||
);
|
||||
parser.pushKey(key);
|
||||
parser.push(transformTimestampArgument(timestamp), value.toString());
|
||||
}
|
||||
|
||||
return args;
|
||||
},
|
||||
transformReply: undefined as unknown as () => ArrayReply<NumberReply | SimpleErrorReply>
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,19 +1,20 @@
|
||||
import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import MGET from './MGET';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('TS.MGET', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('without options', () => {
|
||||
assert.deepEqual(
|
||||
MGET.transformArguments('label=value'),
|
||||
parseArgs(MGET, 'label=value'),
|
||||
['TS.MGET', 'FILTER', 'label=value']
|
||||
);
|
||||
});
|
||||
|
||||
it('with LATEST', () => {
|
||||
assert.deepEqual(
|
||||
MGET.transformArguments('label=value', {
|
||||
parseArgs(MGET, 'label=value', {
|
||||
LATEST: true
|
||||
}),
|
||||
['TS.MGET', 'LATEST', 'FILTER', 'label=value']
|
||||
|
@@ -1,22 +1,21 @@
|
||||
import { CommandArguments, Command, BlobStringReply, ArrayReply, Resp2Reply, MapReply, TuplesReply, TypeMapping } from '@redis/client/dist/lib/RESP/types';
|
||||
import { RedisVariadicArgument, pushVariadicArguments } from '@redis/client/dist/lib/commands/generic-transformers';
|
||||
import { CommandParser } from '@redis/client/lib/client/parser';
|
||||
import { Command, BlobStringReply, ArrayReply, Resp2Reply, MapReply, TuplesReply, TypeMapping } from '@redis/client/lib/RESP/types';
|
||||
import { resp2MapToValue, resp3MapToValue, SampleRawReply, transformSampleReply } from '.';
|
||||
import { RedisVariadicArgument } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
export interface TsMGetOptions {
|
||||
LATEST?: boolean;
|
||||
}
|
||||
|
||||
export function pushLatestArgument(args: CommandArguments, latest?: boolean) {
|
||||
export function parseLatestArgument(parser: CommandParser, latest?: boolean) {
|
||||
if (latest) {
|
||||
args.push('LATEST');
|
||||
parser.push('LATEST');
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
export function pushFilterArgument(args: CommandArguments, filter: RedisVariadicArgument) {
|
||||
args.push('FILTER');
|
||||
return pushVariadicArguments(args, filter);
|
||||
export function parseFilterArgument(parser: CommandParser, filter: RedisVariadicArgument) {
|
||||
parser.push('FILTER');
|
||||
parser.pushVariadic(filter);
|
||||
}
|
||||
|
||||
export type MGetRawReply2 = ArrayReply<
|
||||
@@ -36,11 +35,12 @@ export type MGetRawReply3 = MapReply<
|
||||
>;
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: undefined,
|
||||
NOT_KEYED_COMMAND: true,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(filter: RedisVariadicArgument, options?: TsMGetOptions) {
|
||||
const args = pushLatestArgument(['TS.MGET'], options?.LATEST);
|
||||
return pushFilterArgument(args, filter);
|
||||
parseCommand(parser: CommandParser, filter: RedisVariadicArgument, options?: TsMGetOptions) {
|
||||
parser.push('TS.MGET');
|
||||
parseLatestArgument(parser, options?.LATEST);
|
||||
parseFilterArgument(parser, filter);
|
||||
},
|
||||
transformReply: {
|
||||
2(reply: MGetRawReply2, _, typeMapping?: TypeMapping) {
|
||||
|
@@ -1,11 +1,12 @@
|
||||
import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import MGET_SELECTED_LABELS from './MGET_SELECTED_LABELS';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('TS.MGET_SELECTED_LABELS', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
MGET_SELECTED_LABELS.transformArguments('label=value', 'label'),
|
||||
parseArgs(MGET_SELECTED_LABELS, 'label=value', 'label'),
|
||||
['TS.MGET', 'SELECTED_LABELS', 'label', 'FILTER', 'label=value']
|
||||
);
|
||||
});
|
||||
|
@@ -1,16 +1,17 @@
|
||||
import { Command, BlobStringReply, NullReply } from '@redis/client/dist/lib/RESP/types';
|
||||
import { RedisVariadicArgument } from '@redis/client/dist/lib/commands/generic-transformers';
|
||||
import { TsMGetOptions, pushLatestArgument, pushFilterArgument } from './MGET';
|
||||
import { pushSelectedLabelsArguments } from '.';
|
||||
import { CommandParser } from '@redis/client/lib/client/parser';
|
||||
import { Command, BlobStringReply, NullReply } from '@redis/client/lib/RESP/types';
|
||||
import { RedisVariadicArgument } from '@redis/client/lib/commands/generic-transformers';
|
||||
import { TsMGetOptions, parseLatestArgument, parseFilterArgument } from './MGET';
|
||||
import { parseSelectedLabelsArguments } from '.';
|
||||
import { createTransformMGetLabelsReply } from './MGET_WITHLABELS';
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: undefined,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(filter: RedisVariadicArgument, selectedLabels: RedisVariadicArgument, options?: TsMGetOptions) {
|
||||
let args = pushLatestArgument(['TS.MGET'], options?.LATEST);
|
||||
args = pushSelectedLabelsArguments(args, selectedLabels);
|
||||
return pushFilterArgument(args, filter);
|
||||
parseCommand(parser: CommandParser, filter: RedisVariadicArgument, selectedLabels: RedisVariadicArgument, options?: TsMGetOptions) {
|
||||
parser.push('TS.MGET');
|
||||
parseLatestArgument(parser, options?.LATEST);
|
||||
parseSelectedLabelsArguments(parser, selectedLabels);
|
||||
parseFilterArgument(parser, filter);
|
||||
},
|
||||
transformReply: createTransformMGetLabelsReply<BlobStringReply | NullReply>(),
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,11 +1,12 @@
|
||||
import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import MGET_WITHLABELS from './MGET_WITHLABELS';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('TS.MGET_WITHLABELS', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
MGET_WITHLABELS.transformArguments('label=value'),
|
||||
parseArgs(MGET_WITHLABELS, 'label=value'),
|
||||
['TS.MGET', 'WITHLABELS', 'FILTER', 'label=value']
|
||||
);
|
||||
});
|
||||
|
@@ -1,6 +1,7 @@
|
||||
import { Command, BlobStringReply, ArrayReply, Resp2Reply, MapReply, TuplesReply, TypeMapping } from '@redis/client/dist/lib/RESP/types';
|
||||
import { RedisVariadicArgument } from '@redis/client/dist/lib/commands/generic-transformers';
|
||||
import { TsMGetOptions, pushLatestArgument, pushFilterArgument } from './MGET';
|
||||
import { CommandParser } from '@redis/client/lib/client/parser';
|
||||
import { Command, BlobStringReply, ArrayReply, Resp2Reply, MapReply, TuplesReply, TypeMapping } from '@redis/client/lib/RESP/types';
|
||||
import { RedisVariadicArgument } from '@redis/client/lib/commands/generic-transformers';
|
||||
import { TsMGetOptions, parseLatestArgument, parseFilterArgument } from './MGET';
|
||||
import { RawLabelValue, resp2MapToValue, resp3MapToValue, SampleRawReply, transformRESP2Labels, transformSampleReply } from '.';
|
||||
|
||||
export interface TsMGetWithLabelsOptions extends TsMGetOptions {
|
||||
@@ -50,12 +51,12 @@ export function createTransformMGetLabelsReply<T extends RawLabelValue>() {
|
||||
}
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: undefined,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(filter: RedisVariadicArgument, options?: TsMGetOptions) {
|
||||
const args = pushLatestArgument(['TS.MGET'], options?.LATEST);
|
||||
args.push('WITHLABELS');
|
||||
return pushFilterArgument(args, filter);
|
||||
parseCommand(parser: CommandParser, filter: RedisVariadicArgument, options?: TsMGetWithLabelsOptions) {
|
||||
parser.push('TS.MGET');
|
||||
parseLatestArgument(parser, options?.LATEST);
|
||||
parser.push('WITHLABELS');
|
||||
parseFilterArgument(parser, filter);
|
||||
},
|
||||
transformReply: createTransformMGetLabelsReply<BlobStringReply>(),
|
||||
} as const satisfies Command;
|
||||
|
@@ -2,11 +2,12 @@ import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import MRANGE from './MRANGE';
|
||||
import { TIME_SERIES_AGGREGATION_TYPE } from './CREATERULE';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('TS.MRANGE', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
MRANGE.transformArguments('-', '+', 'label=value', {
|
||||
parseArgs(MRANGE, '-', '+', 'label=value', {
|
||||
LATEST: true,
|
||||
FILTER_BY_TS: [0],
|
||||
FILTER_BY_VALUE: {
|
||||
|
@@ -1,8 +1,9 @@
|
||||
import { Command, ArrayReply, BlobStringReply, Resp2Reply, MapReply, TuplesReply, TypeMapping, RedisArgument } from '@redis/client/dist/lib/RESP/types';
|
||||
import { RedisVariadicArgument } from '@redis/client/dist/lib/commands/generic-transformers';
|
||||
import { CommandParser } from '@redis/client/lib/client/parser';
|
||||
import { Command, ArrayReply, BlobStringReply, Resp2Reply, MapReply, TuplesReply, TypeMapping, RedisArgument } from '@redis/client/lib/RESP/types';
|
||||
import { RedisVariadicArgument } from '@redis/client/lib/commands/generic-transformers';
|
||||
import { resp2MapToValue, resp3MapToValue, SampleRawReply, Timestamp, transformSamplesReply } from '.';
|
||||
import { TsRangeOptions, pushRangeArguments } from './RANGE';
|
||||
import { pushFilterArgument } from './MGET';
|
||||
import { TsRangeOptions, parseRangeArguments } from './RANGE';
|
||||
import { parseFilterArgument } from './MGET';
|
||||
|
||||
export type TsMRangeRawReply2 = ArrayReply<
|
||||
TuplesReply<[
|
||||
@@ -23,26 +24,28 @@ export type TsMRangeRawReply3 = MapReply<
|
||||
|
||||
export function createTransformMRangeArguments(command: RedisArgument) {
|
||||
return (
|
||||
parser: CommandParser,
|
||||
fromTimestamp: Timestamp,
|
||||
toTimestamp: Timestamp,
|
||||
filter: RedisVariadicArgument,
|
||||
options?: TsRangeOptions
|
||||
) => {
|
||||
const args = pushRangeArguments(
|
||||
[command],
|
||||
parser.push(command);
|
||||
parseRangeArguments(
|
||||
parser,
|
||||
fromTimestamp,
|
||||
toTimestamp,
|
||||
options
|
||||
);
|
||||
|
||||
return pushFilterArgument(args, filter);
|
||||
parseFilterArgument(parser, filter);
|
||||
};
|
||||
}
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: undefined,
|
||||
NOT_KEYED_COMMAND: true,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments: createTransformMRangeArguments('TS.MRANGE'),
|
||||
parseCommand: createTransformMRangeArguments('TS.MRANGE'),
|
||||
transformReply: {
|
||||
2(reply: TsMRangeRawReply2, _?: any, typeMapping?: TypeMapping) {
|
||||
return resp2MapToValue(reply, ([_key, _labels, samples]) => {
|
||||
|
@@ -2,11 +2,12 @@ import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import MRANGE_GROUPBY, { TIME_SERIES_REDUCERS } from './MRANGE_GROUPBY';
|
||||
import { TIME_SERIES_AGGREGATION_TYPE } from './CREATERULE';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('TS.MRANGE_GROUPBY', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
MRANGE_GROUPBY.transformArguments('-', '+', 'label=value', {
|
||||
parseArgs(MRANGE_GROUPBY, '-', '+', 'label=value', {
|
||||
REDUCE: TIME_SERIES_REDUCERS.AVG,
|
||||
label: 'label'
|
||||
}, {
|
||||
|
@@ -1,8 +1,9 @@
|
||||
import { Command, ArrayReply, BlobStringReply, Resp2Reply, MapReply, TuplesReply, TypeMapping, RedisArgument, TuplesToMapReply, UnwrapReply } from '@redis/client/dist/lib/RESP/types';
|
||||
import { RedisVariadicArgument } from '@redis/client/dist/lib/commands/generic-transformers';
|
||||
import { CommandParser } from '@redis/client/lib/client/parser';
|
||||
import { Command, ArrayReply, BlobStringReply, Resp2Reply, MapReply, TuplesReply, TypeMapping, RedisArgument, TuplesToMapReply, UnwrapReply } from '@redis/client/lib/RESP/types';
|
||||
import { RedisVariadicArgument } from '@redis/client/lib/commands/generic-transformers';
|
||||
import { resp2MapToValue, resp3MapToValue, SampleRawReply, Timestamp, transformSamplesReply } from '.';
|
||||
import { TsRangeOptions, pushRangeArguments } from './RANGE';
|
||||
import { pushFilterArgument } from './MGET';
|
||||
import { TsRangeOptions, parseRangeArguments } from './RANGE';
|
||||
import { parseFilterArgument } from './MGET';
|
||||
|
||||
export const TIME_SERIES_REDUCERS = {
|
||||
AVG: 'AVG',
|
||||
@@ -24,8 +25,8 @@ export interface TsMRangeGroupBy {
|
||||
REDUCE: TimeSeriesReducer;
|
||||
}
|
||||
|
||||
export function pushGroupByArguments(args: Array<RedisArgument>, groupBy: TsMRangeGroupBy) {
|
||||
args.push('GROUPBY', groupBy.label, 'REDUCE', groupBy.REDUCE);
|
||||
export function parseGroupByArguments(parser: CommandParser, groupBy: TsMRangeGroupBy) {
|
||||
parser.push('GROUPBY', groupBy.label, 'REDUCE', groupBy.REDUCE);
|
||||
}
|
||||
|
||||
export type TsMRangeGroupByRawReply2 = ArrayReply<
|
||||
@@ -52,24 +53,19 @@ export type TsMRangeGroupByRawReply3 = MapReply<
|
||||
|
||||
export function createTransformMRangeGroupByArguments(command: RedisArgument) {
|
||||
return (
|
||||
parser: CommandParser,
|
||||
fromTimestamp: Timestamp,
|
||||
toTimestamp: Timestamp,
|
||||
filter: RedisVariadicArgument,
|
||||
groupBy: TsMRangeGroupBy,
|
||||
options?: TsRangeOptions
|
||||
) => {
|
||||
let args = pushRangeArguments(
|
||||
[command],
|
||||
fromTimestamp,
|
||||
toTimestamp,
|
||||
options
|
||||
);
|
||||
|
||||
args = pushFilterArgument(args, filter);
|
||||
|
||||
pushGroupByArguments(args, groupBy);
|
||||
parser.push(command);
|
||||
parseRangeArguments(parser, fromTimestamp, toTimestamp, options)
|
||||
|
||||
return args;
|
||||
parseFilterArgument(parser, filter);
|
||||
|
||||
parseGroupByArguments(parser, groupBy);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -85,9 +81,8 @@ export function extractResp3MRangeSources(raw: TsMRangeGroupByRawMetadataReply3)
|
||||
}
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: undefined,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments: createTransformMRangeGroupByArguments('TS.MRANGE'),
|
||||
parseCommand: createTransformMRangeGroupByArguments('TS.MRANGE'),
|
||||
transformReply: {
|
||||
2(reply: TsMRangeGroupByRawReply2, _?: any, typeMapping?: TypeMapping) {
|
||||
return resp2MapToValue(reply, ([_key, _labels, samples]) => {
|
||||
|
@@ -2,11 +2,12 @@ import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import MRANGE_SELECTED_LABELS from './MRANGE_SELECTED_LABELS';
|
||||
import { TIME_SERIES_AGGREGATION_TYPE } from './CREATERULE';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('TS.MRANGE_SELECTED_LABELS', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
MRANGE_SELECTED_LABELS.transformArguments('-', '+', 'label', 'label=value', {
|
||||
parseArgs(MRANGE_SELECTED_LABELS, '-', '+', 'label', 'label=value', {
|
||||
FILTER_BY_TS: [0],
|
||||
FILTER_BY_VALUE: {
|
||||
min: 0,
|
||||
|
@@ -1,8 +1,9 @@
|
||||
import { Command, ArrayReply, BlobStringReply, Resp2Reply, MapReply, TuplesReply, TypeMapping, NullReply, RedisArgument } from '@redis/client/dist/lib/RESP/types';
|
||||
import { RedisVariadicArgument } from '@redis/client/dist/lib/commands/generic-transformers';
|
||||
import { pushSelectedLabelsArguments, resp2MapToValue, resp3MapToValue, SampleRawReply, Timestamp, transformRESP2Labels, transformSamplesReply } from '.';
|
||||
import { TsRangeOptions, pushRangeArguments } from './RANGE';
|
||||
import { pushFilterArgument } from './MGET';
|
||||
import { CommandParser } from '@redis/client/lib/client/parser';
|
||||
import { Command, ArrayReply, BlobStringReply, Resp2Reply, MapReply, TuplesReply, TypeMapping, NullReply, RedisArgument } from '@redis/client/lib/RESP/types';
|
||||
import { RedisVariadicArgument } from '@redis/client/lib/commands/generic-transformers';
|
||||
import { parseSelectedLabelsArguments, resp2MapToValue, resp3MapToValue, SampleRawReply, Timestamp, transformRESP2Labels, transformSamplesReply } from '.';
|
||||
import { TsRangeOptions, parseRangeArguments } from './RANGE';
|
||||
import { parseFilterArgument } from './MGET';
|
||||
|
||||
export type TsMRangeSelectedLabelsRawReply2 = ArrayReply<
|
||||
TuplesReply<[
|
||||
@@ -26,29 +27,30 @@ export type TsMRangeSelectedLabelsRawReply3 = MapReply<
|
||||
|
||||
export function createTransformMRangeSelectedLabelsArguments(command: RedisArgument) {
|
||||
return (
|
||||
parser: CommandParser,
|
||||
fromTimestamp: Timestamp,
|
||||
toTimestamp: Timestamp,
|
||||
selectedLabels: RedisVariadicArgument,
|
||||
filter: RedisVariadicArgument,
|
||||
options?: TsRangeOptions
|
||||
) => {
|
||||
let args = pushRangeArguments(
|
||||
[command],
|
||||
parser.push(command);
|
||||
parseRangeArguments(
|
||||
parser,
|
||||
fromTimestamp,
|
||||
toTimestamp,
|
||||
options
|
||||
);
|
||||
|
||||
args = pushSelectedLabelsArguments(args, selectedLabels);
|
||||
parseSelectedLabelsArguments(parser, selectedLabels);
|
||||
|
||||
return pushFilterArgument(args, filter);
|
||||
parseFilterArgument(parser, filter);
|
||||
};
|
||||
}
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: undefined,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments: createTransformMRangeSelectedLabelsArguments('TS.MRANGE'),
|
||||
parseCommand: createTransformMRangeSelectedLabelsArguments('TS.MRANGE'),
|
||||
transformReply: {
|
||||
2(reply: TsMRangeSelectedLabelsRawReply2, _?: any, typeMapping?: TypeMapping) {
|
||||
return resp2MapToValue(reply, ([_key, labels, samples]) => {
|
||||
|
@@ -3,11 +3,12 @@ import testUtils, { GLOBAL } from '../test-utils';
|
||||
import MRANGE_SELECTED_LABELS_GROUPBY from './MRANGE_SELECTED_LABELS_GROUPBY';
|
||||
import { TIME_SERIES_REDUCERS } from './MRANGE_GROUPBY';
|
||||
import { TIME_SERIES_AGGREGATION_TYPE } from './CREATERULE';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('TS.MRANGE_SELECTED_LABELS_GROUPBY', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
MRANGE_SELECTED_LABELS_GROUPBY.transformArguments('-', '+', 'label', 'label=value', {
|
||||
parseArgs(MRANGE_SELECTED_LABELS_GROUPBY, '-', '+', 'label', 'label=value', {
|
||||
REDUCE: TIME_SERIES_REDUCERS.AVG,
|
||||
label: 'label'
|
||||
}, {
|
||||
|
@@ -1,9 +1,10 @@
|
||||
import { Command, ArrayReply, BlobStringReply, MapReply, TuplesReply, RedisArgument, NullReply } from '@redis/client/dist/lib/RESP/types';
|
||||
import { RedisVariadicArgument } from '@redis/client/dist/lib/commands/generic-transformers';
|
||||
import { pushSelectedLabelsArguments, resp3MapToValue, SampleRawReply, Timestamp, transformSamplesReply } from '.';
|
||||
import { TsRangeOptions, pushRangeArguments } from './RANGE';
|
||||
import { extractResp3MRangeSources, pushGroupByArguments, TsMRangeGroupBy, TsMRangeGroupByRawMetadataReply3 } from './MRANGE_GROUPBY';
|
||||
import { pushFilterArgument } from './MGET';
|
||||
import { CommandParser } from '@redis/client/lib/client/parser';
|
||||
import { Command, ArrayReply, BlobStringReply, MapReply, TuplesReply, RedisArgument, NullReply } from '@redis/client/lib/RESP/types';
|
||||
import { RedisVariadicArgument } from '@redis/client/lib/commands/generic-transformers';
|
||||
import { parseSelectedLabelsArguments, resp3MapToValue, SampleRawReply, Timestamp, transformSamplesReply } from '.';
|
||||
import { TsRangeOptions, parseRangeArguments } from './RANGE';
|
||||
import { extractResp3MRangeSources, parseGroupByArguments, TsMRangeGroupBy, TsMRangeGroupByRawMetadataReply3 } from './MRANGE_GROUPBY';
|
||||
import { parseFilterArgument } from './MGET';
|
||||
import MRANGE_SELECTED_LABELS from './MRANGE_SELECTED_LABELS';
|
||||
|
||||
export type TsMRangeWithLabelsGroupByRawReply3 = MapReply<
|
||||
@@ -20,6 +21,7 @@ export function createMRangeSelectedLabelsGroupByTransformArguments(
|
||||
command: RedisArgument
|
||||
) {
|
||||
return (
|
||||
parser: CommandParser,
|
||||
fromTimestamp: Timestamp,
|
||||
toTimestamp: Timestamp,
|
||||
selectedLabels: RedisVariadicArgument,
|
||||
@@ -27,27 +29,25 @@ export function createMRangeSelectedLabelsGroupByTransformArguments(
|
||||
groupBy: TsMRangeGroupBy,
|
||||
options?: TsRangeOptions
|
||||
) => {
|
||||
let args = pushRangeArguments(
|
||||
[command],
|
||||
parser.push(command);
|
||||
parseRangeArguments(
|
||||
parser,
|
||||
fromTimestamp,
|
||||
toTimestamp,
|
||||
options
|
||||
);
|
||||
|
||||
args = pushSelectedLabelsArguments(args, selectedLabels);
|
||||
parseSelectedLabelsArguments(parser, selectedLabels);
|
||||
|
||||
args = pushFilterArgument(args, filter);
|
||||
parseFilterArgument(parser, filter);
|
||||
|
||||
pushGroupByArguments(args, groupBy);
|
||||
|
||||
return args;
|
||||
parseGroupByArguments(parser, groupBy);
|
||||
};
|
||||
}
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: undefined,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments: createMRangeSelectedLabelsGroupByTransformArguments('TS.MRANGE'),
|
||||
parseCommand: createMRangeSelectedLabelsGroupByTransformArguments('TS.MRANGE'),
|
||||
transformReply: {
|
||||
2: MRANGE_SELECTED_LABELS.transformReply[2],
|
||||
3(reply: TsMRangeWithLabelsGroupByRawReply3) {
|
||||
|
@@ -2,11 +2,12 @@ import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import MRANGE_WITHLABELS from './MRANGE_WITHLABELS';
|
||||
import { TIME_SERIES_AGGREGATION_TYPE } from './CREATERULE';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('TS.MRANGE_WITHLABELS', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
MRANGE_WITHLABELS.transformArguments('-', '+', 'label=value', {
|
||||
parseArgs(MRANGE_WITHLABELS, '-', '+', 'label=value', {
|
||||
LATEST: true,
|
||||
FILTER_BY_TS: [0],
|
||||
FILTER_BY_VALUE: {
|
||||
|
@@ -1,8 +1,9 @@
|
||||
import { Command, UnwrapReply, ArrayReply, BlobStringReply, Resp2Reply, MapReply, TuplesReply, TypeMapping, RedisArgument } from '@redis/client/dist/lib/RESP/types';
|
||||
import { RedisVariadicArgument } from '@redis/client/dist/lib/commands/generic-transformers';
|
||||
import { CommandParser } from '@redis/client/lib/client/parser';
|
||||
import { Command, UnwrapReply, ArrayReply, BlobStringReply, Resp2Reply, MapReply, TuplesReply, TypeMapping, RedisArgument } from '@redis/client/lib/RESP/types';
|
||||
import { RedisVariadicArgument } from '@redis/client/lib/commands/generic-transformers';
|
||||
import { resp2MapToValue, resp3MapToValue, SampleRawReply, Timestamp, transformSamplesReply } from '.';
|
||||
import { TsRangeOptions, pushRangeArguments } from './RANGE';
|
||||
import { pushFilterArgument } from './MGET';
|
||||
import { TsRangeOptions, parseRangeArguments } from './RANGE';
|
||||
import { parseFilterArgument } from './MGET';
|
||||
|
||||
export type TsMRangeWithLabelsRawReply2 = ArrayReply<
|
||||
TuplesReply<[
|
||||
@@ -26,28 +27,30 @@ export type TsMRangeWithLabelsRawReply3 = MapReply<
|
||||
|
||||
export function createTransformMRangeWithLabelsArguments(command: RedisArgument) {
|
||||
return (
|
||||
parser: CommandParser,
|
||||
fromTimestamp: Timestamp,
|
||||
toTimestamp: Timestamp,
|
||||
filter: RedisVariadicArgument,
|
||||
options?: TsRangeOptions
|
||||
) => {
|
||||
const args = pushRangeArguments(
|
||||
[command],
|
||||
parser.push(command);
|
||||
parseRangeArguments(
|
||||
parser,
|
||||
fromTimestamp,
|
||||
toTimestamp,
|
||||
options
|
||||
);
|
||||
|
||||
args.push('WITHLABELS');
|
||||
parser.push('WITHLABELS');
|
||||
|
||||
return pushFilterArgument(args, filter);
|
||||
parseFilterArgument(parser, filter);
|
||||
};
|
||||
}
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: undefined,
|
||||
NOT_KEYED_COMMAND: true,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments: createTransformMRangeWithLabelsArguments('TS.MRANGE'),
|
||||
parseCommand: createTransformMRangeWithLabelsArguments('TS.MRANGE'),
|
||||
transformReply: {
|
||||
2(reply: TsMRangeWithLabelsRawReply2, _?: any, typeMapping?: TypeMapping) {
|
||||
return resp2MapToValue(reply, ([_key, labels, samples]) => {
|
||||
|
@@ -3,11 +3,12 @@ import testUtils, { GLOBAL } from '../test-utils';
|
||||
import MRANGE_WITHLABELS_GROUPBY from './MRANGE_WITHLABELS_GROUPBY';
|
||||
import { TIME_SERIES_REDUCERS } from './MRANGE_GROUPBY';
|
||||
import { TIME_SERIES_AGGREGATION_TYPE } from './CREATERULE';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('TS.MRANGE_WITHLABELS_GROUPBY', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
MRANGE_WITHLABELS_GROUPBY.transformArguments('-', '+', 'label=value', {
|
||||
parseArgs(MRANGE_WITHLABELS_GROUPBY, '-', '+', 'label=value', {
|
||||
label: 'label',
|
||||
REDUCE: TIME_SERIES_REDUCERS.AVG
|
||||
}, {
|
||||
|
@@ -1,9 +1,10 @@
|
||||
import { Command, ArrayReply, BlobStringReply, Resp2Reply, MapReply, TuplesReply, TypeMapping, RedisArgument } from '@redis/client/dist/lib/RESP/types';
|
||||
import { RedisVariadicArgument } from '@redis/client/dist/lib/commands/generic-transformers';
|
||||
import { CommandParser } from '@redis/client/lib/client/parser';
|
||||
import { Command, ArrayReply, BlobStringReply, Resp2Reply, MapReply, TuplesReply, TypeMapping, RedisArgument } from '@redis/client/lib/RESP/types';
|
||||
import { RedisVariadicArgument } from '@redis/client/lib/commands/generic-transformers';
|
||||
import { resp2MapToValue, resp3MapToValue, SampleRawReply, Timestamp, transformRESP2LabelsWithSources, transformSamplesReply } from '.';
|
||||
import { TsRangeOptions, pushRangeArguments } from './RANGE';
|
||||
import { extractResp3MRangeSources, pushGroupByArguments, TsMRangeGroupBy, TsMRangeGroupByRawMetadataReply3 } from './MRANGE_GROUPBY';
|
||||
import { pushFilterArgument } from './MGET';
|
||||
import { TsRangeOptions, parseRangeArguments } from './RANGE';
|
||||
import { extractResp3MRangeSources, parseGroupByArguments, TsMRangeGroupBy, TsMRangeGroupByRawMetadataReply3 } from './MRANGE_GROUPBY';
|
||||
import { parseFilterArgument } from './MGET';
|
||||
|
||||
export type TsMRangeWithLabelsGroupByRawReply2 = ArrayReply<
|
||||
TuplesReply<[
|
||||
@@ -28,33 +29,32 @@ export type TsMRangeWithLabelsGroupByRawReply3 = MapReply<
|
||||
|
||||
export function createMRangeWithLabelsGroupByTransformArguments(command: RedisArgument) {
|
||||
return (
|
||||
parser: CommandParser,
|
||||
fromTimestamp: Timestamp,
|
||||
toTimestamp: Timestamp,
|
||||
filter: RedisVariadicArgument,
|
||||
groupBy: TsMRangeGroupBy,
|
||||
options?: TsRangeOptions
|
||||
) => {
|
||||
let args = pushRangeArguments(
|
||||
[command],
|
||||
parser.push(command);
|
||||
parseRangeArguments(
|
||||
parser,
|
||||
fromTimestamp,
|
||||
toTimestamp,
|
||||
options
|
||||
);
|
||||
|
||||
args.push('WITHLABELS');
|
||||
parser.push('WITHLABELS');
|
||||
|
||||
args = pushFilterArgument(args, filter);
|
||||
parseFilterArgument(parser, filter);
|
||||
|
||||
pushGroupByArguments(args, groupBy);
|
||||
|
||||
return args;
|
||||
};
|
||||
parseGroupByArguments(parser, groupBy);
|
||||
};
|
||||
}
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: undefined,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments: createMRangeWithLabelsGroupByTransformArguments('TS.MRANGE'),
|
||||
parseCommand: createMRangeWithLabelsGroupByTransformArguments('TS.MRANGE'),
|
||||
transformReply: {
|
||||
2(reply: TsMRangeWithLabelsGroupByRawReply2, _?: any, typeMapping?: TypeMapping) {
|
||||
return resp2MapToValue(reply, ([_key, labels, samples]) => {
|
||||
|
@@ -2,11 +2,12 @@ import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import MREVRANGE from './MREVRANGE';
|
||||
import { TIME_SERIES_AGGREGATION_TYPE } from './CREATERULE';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('TS.MREVRANGE', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
MREVRANGE.transformArguments('-', '+', 'label=value', {
|
||||
parseArgs(MREVRANGE, '-', '+', 'label=value', {
|
||||
LATEST: true,
|
||||
FILTER_BY_TS: [0],
|
||||
FILTER_BY_VALUE: {
|
||||
|
@@ -1,9 +1,9 @@
|
||||
import { Command } from '@redis/client/dist/lib/RESP/types';
|
||||
import { Command } from '@redis/client/lib/RESP/types';
|
||||
import MRANGE, { createTransformMRangeArguments } from './MRANGE';
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: MRANGE.FIRST_KEY_INDEX,
|
||||
NOT_KEYED_COMMAND: MRANGE.NOT_KEYED_COMMAND,
|
||||
IS_READ_ONLY: MRANGE.IS_READ_ONLY,
|
||||
transformArguments: createTransformMRangeArguments('TS.MREVRANGE'),
|
||||
parseCommand: createTransformMRangeArguments('TS.MREVRANGE'),
|
||||
transformReply: MRANGE.transformReply,
|
||||
} as const satisfies Command;
|
||||
|
@@ -3,11 +3,12 @@ import testUtils, { GLOBAL } from '../test-utils';
|
||||
import MREVRANGE_GROUPBY from './MREVRANGE_GROUPBY';
|
||||
import { TIME_SERIES_REDUCERS } from './MRANGE_GROUPBY';
|
||||
import { TIME_SERIES_AGGREGATION_TYPE } from './CREATERULE';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('TS.MREVRANGE_GROUPBY', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
MREVRANGE_GROUPBY.transformArguments('-', '+', 'label=value', {
|
||||
parseArgs(MREVRANGE_GROUPBY, '-', '+', 'label=value', {
|
||||
REDUCE: TIME_SERIES_REDUCERS.AVG,
|
||||
label: 'label'
|
||||
}, {
|
||||
|
@@ -1,9 +1,8 @@
|
||||
import { Command } from '@redis/client/dist/lib/RESP/types';
|
||||
import { Command } from '@redis/client/lib/RESP/types';
|
||||
import MRANGE_GROUPBY, { createTransformMRangeGroupByArguments } from './MRANGE_GROUPBY';
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: MRANGE_GROUPBY.FIRST_KEY_INDEX,
|
||||
IS_READ_ONLY: MRANGE_GROUPBY.IS_READ_ONLY,
|
||||
transformArguments: createTransformMRangeGroupByArguments('TS.MREVRANGE'),
|
||||
parseCommand: createTransformMRangeGroupByArguments('TS.MREVRANGE'),
|
||||
transformReply: MRANGE_GROUPBY.transformReply,
|
||||
} as const satisfies Command;
|
||||
|
@@ -2,11 +2,12 @@ import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import MREVRANGE_SELECTED_LABELS from './MREVRANGE_SELECTED_LABELS';
|
||||
import { TIME_SERIES_AGGREGATION_TYPE } from './CREATERULE';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('TS.MREVRANGE_SELECTED_LABELS', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
MREVRANGE_SELECTED_LABELS.transformArguments('-', '+', 'label', 'label=value', {
|
||||
parseArgs(MREVRANGE_SELECTED_LABELS, '-', '+', 'label', 'label=value', {
|
||||
FILTER_BY_TS: [0],
|
||||
FILTER_BY_VALUE: {
|
||||
min: 0,
|
||||
|
@@ -1,9 +1,8 @@
|
||||
import { Command } from '@redis/client/dist/lib/RESP/types';
|
||||
import { Command } from '@redis/client/lib/RESP/types';
|
||||
import MRANGE_SELECTED_LABELS, { createTransformMRangeSelectedLabelsArguments } from './MRANGE_SELECTED_LABELS';
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: MRANGE_SELECTED_LABELS.FIRST_KEY_INDEX,
|
||||
IS_READ_ONLY: MRANGE_SELECTED_LABELS.IS_READ_ONLY,
|
||||
transformArguments: createTransformMRangeSelectedLabelsArguments('TS.MREVRANGE'),
|
||||
parseCommand: createTransformMRangeSelectedLabelsArguments('TS.MREVRANGE'),
|
||||
transformReply: MRANGE_SELECTED_LABELS.transformReply,
|
||||
} as const satisfies Command;
|
||||
|
@@ -3,11 +3,12 @@ import testUtils, { GLOBAL } from '../test-utils';
|
||||
import MREVRANGE_SELECTED_LABELS_GROUPBY from './MREVRANGE_SELECTED_LABELS_GROUPBY';
|
||||
import { TIME_SERIES_REDUCERS } from './MRANGE_GROUPBY';
|
||||
import { TIME_SERIES_AGGREGATION_TYPE } from './CREATERULE';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('TS.MREVRANGE_SELECTED_LABELS_GROUPBY', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
MREVRANGE_SELECTED_LABELS_GROUPBY.transformArguments('-', '+', 'label', 'label=value', {
|
||||
parseArgs(MREVRANGE_SELECTED_LABELS_GROUPBY, '-', '+', 'label', 'label=value', {
|
||||
REDUCE: TIME_SERIES_REDUCERS.AVG,
|
||||
label: 'label'
|
||||
}, {
|
||||
|
@@ -1,9 +1,8 @@
|
||||
import { Command } from '@redis/client/dist/lib/RESP/types';
|
||||
import { Command } from '@redis/client/lib/RESP/types';
|
||||
import MRANGE_SELECTED_LABELS_GROUPBY, { createMRangeSelectedLabelsGroupByTransformArguments } from './MRANGE_SELECTED_LABELS_GROUPBY';
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: MRANGE_SELECTED_LABELS_GROUPBY.FIRST_KEY_INDEX,
|
||||
IS_READ_ONLY: MRANGE_SELECTED_LABELS_GROUPBY.IS_READ_ONLY,
|
||||
transformArguments: createMRangeSelectedLabelsGroupByTransformArguments('TS.MREVRANGE'),
|
||||
parseCommand: createMRangeSelectedLabelsGroupByTransformArguments('TS.MREVRANGE'),
|
||||
transformReply: MRANGE_SELECTED_LABELS_GROUPBY.transformReply,
|
||||
} as const satisfies Command;
|
||||
|
@@ -2,11 +2,12 @@ import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import MREVRANGE_WITHLABELS from './MREVRANGE_WITHLABELS';
|
||||
import { TIME_SERIES_AGGREGATION_TYPE } from './CREATERULE';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('TS.MREVRANGE_WITHLABELS', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
MREVRANGE_WITHLABELS.transformArguments('-', '+', 'label=value', {
|
||||
parseArgs(MREVRANGE_WITHLABELS, '-', '+', 'label=value', {
|
||||
LATEST: true,
|
||||
FILTER_BY_TS: [0],
|
||||
FILTER_BY_VALUE: {
|
||||
|
@@ -1,9 +1,9 @@
|
||||
import { Command } from '@redis/client/dist/lib/RESP/types';
|
||||
import { Command } from '@redis/client/lib/RESP/types';
|
||||
import MRANGE_WITHLABELS, { createTransformMRangeWithLabelsArguments } from './MRANGE_WITHLABELS';
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: MRANGE_WITHLABELS.FIRST_KEY_INDEX,
|
||||
NOT_KEYED_COMMAND: MRANGE_WITHLABELS.NOT_KEYED_COMMAND,
|
||||
IS_READ_ONLY: MRANGE_WITHLABELS.IS_READ_ONLY,
|
||||
transformArguments: createTransformMRangeWithLabelsArguments('TS.MREVRANGE'),
|
||||
parseCommand: createTransformMRangeWithLabelsArguments('TS.MREVRANGE'),
|
||||
transformReply: MRANGE_WITHLABELS.transformReply,
|
||||
} as const satisfies Command;
|
||||
|
@@ -3,11 +3,12 @@ import testUtils, { GLOBAL } from '../test-utils';
|
||||
import MREVRANGE_WITHLABELS_GROUPBY from './MREVRANGE_WITHLABELS_GROUPBY';
|
||||
import { TIME_SERIES_REDUCERS } from './MRANGE_GROUPBY';
|
||||
import { TIME_SERIES_AGGREGATION_TYPE } from './CREATERULE';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('TS.MREVRANGE_WITHLABELS_GROUPBY', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
MREVRANGE_WITHLABELS_GROUPBY.transformArguments('-', '+', 'label=value', {
|
||||
parseArgs(MREVRANGE_WITHLABELS_GROUPBY, '-', '+', 'label=value', {
|
||||
label: 'label',
|
||||
REDUCE: TIME_SERIES_REDUCERS.AVG
|
||||
}, {
|
||||
|
@@ -1,9 +1,8 @@
|
||||
import { Command } from '@redis/client/dist/lib/RESP/types';
|
||||
import { Command } from '@redis/client/lib/RESP/types';
|
||||
import MRANGE_WITHLABELS_GROUPBY, { createMRangeWithLabelsGroupByTransformArguments } from './MRANGE_WITHLABELS_GROUPBY';
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: MRANGE_WITHLABELS_GROUPBY.FIRST_KEY_INDEX,
|
||||
IS_READ_ONLY: MRANGE_WITHLABELS_GROUPBY.IS_READ_ONLY,
|
||||
transformArguments: createMRangeWithLabelsGroupByTransformArguments('TS.MREVRANGE'),
|
||||
parseCommand: createMRangeWithLabelsGroupByTransformArguments('TS.MREVRANGE'),
|
||||
transformReply: MRANGE_WITHLABELS_GROUPBY.transformReply,
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,19 +1,20 @@
|
||||
import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import QUERYINDEX from './QUERYINDEX';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('TS.QUERYINDEX', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('single filter', () => {
|
||||
assert.deepEqual(
|
||||
QUERYINDEX.transformArguments('*'),
|
||||
parseArgs(QUERYINDEX, '*'),
|
||||
['TS.QUERYINDEX', '*']
|
||||
);
|
||||
});
|
||||
|
||||
it('multiple filters', () => {
|
||||
assert.deepEqual(
|
||||
QUERYINDEX.transformArguments(['a=1', 'b=2']),
|
||||
parseArgs(QUERYINDEX, ['a=1', 'b=2']),
|
||||
['TS.QUERYINDEX', 'a=1', 'b=2']
|
||||
);
|
||||
});
|
||||
|
@@ -1,11 +1,13 @@
|
||||
import { ArrayReply, BlobStringReply, SetReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||
import { RedisVariadicArgument, pushVariadicArguments } from '@redis/client/dist/lib/commands/generic-transformers';
|
||||
import { CommandParser } from '@redis/client/lib/client/parser';
|
||||
import { ArrayReply, BlobStringReply, SetReply, Command } from '@redis/client/lib/RESP/types';
|
||||
import { RedisVariadicArgument } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: undefined,
|
||||
NOT_KEYED_COMMAND: true,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(filter: RedisVariadicArgument) {
|
||||
return pushVariadicArguments(['TS.QUERYINDEX'], filter);
|
||||
parseCommand(parser: CommandParser, filter: RedisVariadicArgument) {
|
||||
parser.push('TS.QUERYINDEX');
|
||||
parser.pushVariadic(filter);
|
||||
},
|
||||
transformReply: {
|
||||
2: undefined as unknown as () => ArrayReply<BlobStringReply>,
|
||||
|
@@ -2,11 +2,12 @@ import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import RANGE from './RANGE';
|
||||
import { TIME_SERIES_AGGREGATION_TYPE } from './CREATERULE';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('TS.RANGE', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
RANGE.transformArguments('key', '-', '+', {
|
||||
parseArgs(RANGE, 'key', '-', '+', {
|
||||
FILTER_BY_TS: [0],
|
||||
FILTER_BY_VALUE: {
|
||||
min: 1,
|
||||
|
@@ -1,7 +1,8 @@
|
||||
import { CommandArguments, RedisArgument, Command } from '@redis/client/dist/lib/RESP/types';
|
||||
import { CommandParser } from '@redis/client/lib/client/parser';
|
||||
import { RedisArgument, Command } from '@redis/client/lib/RESP/types';
|
||||
import { Timestamp, transformTimestampArgument, SamplesRawReply, transformSamplesReply } from '.';
|
||||
import { TimeSeriesAggregationType } from './CREATERULE';
|
||||
import { Resp2Reply } from '@redis/client/dist/lib/RESP/types';
|
||||
import { Resp2Reply } from '@redis/client/lib/RESP/types';
|
||||
|
||||
export const TIME_SERIES_BUCKET_TIMESTAMP = {
|
||||
LOW: '-',
|
||||
@@ -29,30 +30,30 @@ export interface TsRangeOptions {
|
||||
};
|
||||
}
|
||||
|
||||
export function pushRangeArguments(
|
||||
args: CommandArguments,
|
||||
export function parseRangeArguments(
|
||||
parser: CommandParser,
|
||||
fromTimestamp: Timestamp,
|
||||
toTimestamp: Timestamp,
|
||||
options?: TsRangeOptions
|
||||
) {
|
||||
args.push(
|
||||
parser.push(
|
||||
transformTimestampArgument(fromTimestamp),
|
||||
transformTimestampArgument(toTimestamp)
|
||||
);
|
||||
|
||||
if (options?.LATEST) {
|
||||
args.push('LATEST');
|
||||
parser.push('LATEST');
|
||||
}
|
||||
|
||||
if (options?.FILTER_BY_TS) {
|
||||
args.push('FILTER_BY_TS');
|
||||
parser.push('FILTER_BY_TS');
|
||||
for (const timestamp of options.FILTER_BY_TS) {
|
||||
args.push(transformTimestampArgument(timestamp));
|
||||
parser.push(transformTimestampArgument(timestamp));
|
||||
}
|
||||
}
|
||||
|
||||
if (options?.FILTER_BY_VALUE) {
|
||||
args.push(
|
||||
parser.push(
|
||||
'FILTER_BY_VALUE',
|
||||
options.FILTER_BY_VALUE.min.toString(),
|
||||
options.FILTER_BY_VALUE.max.toString()
|
||||
@@ -60,54 +61,52 @@ export function pushRangeArguments(
|
||||
}
|
||||
|
||||
if (options?.COUNT !== undefined) {
|
||||
args.push('COUNT', options.COUNT.toString());
|
||||
parser.push('COUNT', options.COUNT.toString());
|
||||
}
|
||||
|
||||
if (options?.AGGREGATION) {
|
||||
if (options?.ALIGN !== undefined) {
|
||||
args.push('ALIGN', transformTimestampArgument(options.ALIGN));
|
||||
parser.push('ALIGN', transformTimestampArgument(options.ALIGN));
|
||||
}
|
||||
|
||||
args.push(
|
||||
parser.push(
|
||||
'AGGREGATION',
|
||||
options.AGGREGATION.type,
|
||||
transformTimestampArgument(options.AGGREGATION.timeBucket)
|
||||
);
|
||||
|
||||
if (options.AGGREGATION.BUCKETTIMESTAMP) {
|
||||
args.push(
|
||||
parser.push(
|
||||
'BUCKETTIMESTAMP',
|
||||
options.AGGREGATION.BUCKETTIMESTAMP
|
||||
);
|
||||
}
|
||||
|
||||
if (options.AGGREGATION.EMPTY) {
|
||||
args.push('EMPTY');
|
||||
parser.push('EMPTY');
|
||||
}
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
export function transformRangeArguments(
|
||||
command: RedisArgument,
|
||||
parser: CommandParser,
|
||||
key: RedisArgument,
|
||||
fromTimestamp: Timestamp,
|
||||
toTimestamp: Timestamp,
|
||||
options?: TsRangeOptions
|
||||
) {
|
||||
return pushRangeArguments(
|
||||
[command, key],
|
||||
fromTimestamp,
|
||||
toTimestamp,
|
||||
options
|
||||
);
|
||||
parser.pushKey(key);
|
||||
parseRangeArguments(parser, fromTimestamp, toTimestamp, options);
|
||||
}
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments: transformRangeArguments.bind(undefined, 'TS.RANGE'),
|
||||
parseCommand(...args: Parameters<typeof transformRangeArguments>) {
|
||||
const parser = args[0];
|
||||
|
||||
parser.push('TS.RANGE');
|
||||
transformRangeArguments(...args);
|
||||
},
|
||||
transformReply: {
|
||||
2(reply: Resp2Reply<SamplesRawReply>) {
|
||||
return transformSamplesReply[2](reply);
|
||||
|
@@ -2,11 +2,12 @@ import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import REVRANGE from './REVRANGE';
|
||||
import { TIME_SERIES_AGGREGATION_TYPE } from '../index';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('TS.REVRANGE', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
REVRANGE.transformArguments('key', '-', '+', {
|
||||
parseArgs(REVRANGE, 'key', '-', '+', {
|
||||
FILTER_BY_TS: [0],
|
||||
FILTER_BY_VALUE: {
|
||||
min: 1,
|
||||
|
@@ -1,9 +1,13 @@
|
||||
import { Command } from '@redis/client/dist/lib/RESP/types';
|
||||
import { Command } from '@redis/client/lib/RESP/types';
|
||||
import RANGE, { transformRangeArguments } from './RANGE';
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: RANGE.FIRST_KEY_INDEX,
|
||||
IS_READ_ONLY: RANGE.IS_READ_ONLY,
|
||||
transformArguments: transformRangeArguments.bind(undefined, 'TS.REVRANGE'),
|
||||
parseCommand(...args: Parameters<typeof transformRangeArguments>) {
|
||||
const parser = args[0];
|
||||
|
||||
parser.push('TS.REVRANGE');
|
||||
transformRangeArguments(...args);
|
||||
},
|
||||
transformReply: RANGE.transformReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// import { RedisCommandArguments } from '@redis/client/dist/lib/commands';
|
||||
// import { RedisCommandArguments } from '@redis/client/lib/commands';
|
||||
// import { strict as assert } from 'node:assert';
|
||||
// import {
|
||||
// transformTimestampArgument,
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import type { DoubleReply, NumberReply, RedisArgument, RedisCommands, TuplesReply, UnwrapReply, Resp2Reply, ArrayReply, BlobStringReply, MapReply, NullReply, TypeMapping, ReplyUnion, RespType } from '@redis/client/lib/RESP/types';
|
||||
import type { DoubleReply, NumberReply, RedisCommands, TuplesReply, UnwrapReply, Resp2Reply, ArrayReply, BlobStringReply, MapReply, NullReply, TypeMapping, ReplyUnion, RespType } from '@redis/client/lib/RESP/types';
|
||||
import ADD, { TsIgnoreOptions } from './ADD';
|
||||
import ALTER from './ALTER';
|
||||
import CREATE from './CREATE';
|
||||
@@ -29,7 +29,8 @@ import MREVRANGE from './MREVRANGE';
|
||||
import QUERYINDEX from './QUERYINDEX';
|
||||
import RANGE from './RANGE';
|
||||
import REVRANGE from './REVRANGE';
|
||||
import { RedisVariadicArgument, pushVariadicArguments } from '@redis/client/lib/commands/generic-transformers';
|
||||
import { RedisVariadicArgument } from '@redis/client/lib/commands/generic-transformers';
|
||||
import { CommandParser } from '@redis/client/lib/client/parser';
|
||||
import { RESP_TYPES } from '@redis/client/lib/RESP/decoder';
|
||||
|
||||
export default {
|
||||
@@ -95,15 +96,15 @@ export default {
|
||||
revRange: REVRANGE
|
||||
} as const satisfies RedisCommands;
|
||||
|
||||
export function pushIgnoreArgument(args: Array<RedisArgument>, ignore?: TsIgnoreOptions) {
|
||||
export function parseIgnoreArgument(parser: CommandParser, ignore?: TsIgnoreOptions) {
|
||||
if (ignore !== undefined) {
|
||||
args.push('IGNORE', ignore.maxTimeDiff.toString(), ignore.maxValDiff.toString());
|
||||
parser.push('IGNORE', ignore.maxTimeDiff.toString(), ignore.maxValDiff.toString());
|
||||
}
|
||||
}
|
||||
|
||||
export function pushRetentionArgument(args: Array<RedisArgument>, retention?: number) {
|
||||
export function parseRetentionArgument(parser: CommandParser, retention?: number) {
|
||||
if (retention !== undefined) {
|
||||
args.push('RETENTION', retention.toString());
|
||||
parser.push('RETENTION', retention.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,15 +115,15 @@ export const TIME_SERIES_ENCODING = {
|
||||
|
||||
export type TimeSeriesEncoding = typeof TIME_SERIES_ENCODING[keyof typeof TIME_SERIES_ENCODING];
|
||||
|
||||
export function pushEncodingArgument(args: Array<RedisArgument>, encoding?: TimeSeriesEncoding) {
|
||||
export function parseEncodingArgument(parser: CommandParser, encoding?: TimeSeriesEncoding) {
|
||||
if (encoding !== undefined) {
|
||||
args.push('ENCODING', encoding);
|
||||
parser.push('ENCODING', encoding);
|
||||
}
|
||||
}
|
||||
|
||||
export function pushChunkSizeArgument(args: Array<RedisArgument>, chunkSize?: number) {
|
||||
export function parseChunkSizeArgument(parser: CommandParser, chunkSize?: number) {
|
||||
if (chunkSize !== undefined) {
|
||||
args.push('CHUNK_SIZE', chunkSize.toString());
|
||||
parser.push('CHUNK_SIZE', chunkSize.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,9 +138,9 @@ export const TIME_SERIES_DUPLICATE_POLICIES = {
|
||||
|
||||
export type TimeSeriesDuplicatePolicies = typeof TIME_SERIES_DUPLICATE_POLICIES[keyof typeof TIME_SERIES_DUPLICATE_POLICIES];
|
||||
|
||||
export function pushDuplicatePolicy(args: Array<RedisArgument>, duplicatePolicy?: TimeSeriesDuplicatePolicies) {
|
||||
export function parseDuplicatePolicy(parser: CommandParser, duplicatePolicy?: TimeSeriesDuplicatePolicies) {
|
||||
if (duplicatePolicy !== undefined) {
|
||||
args.push('DUPLICATE_POLICY', duplicatePolicy);
|
||||
parser.push('DUPLICATE_POLICY', duplicatePolicy);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,16 +160,14 @@ export type Labels = {
|
||||
[label: string]: string;
|
||||
};
|
||||
|
||||
export function pushLabelsArgument(args: Array<RedisArgument>, labels?: Labels) {
|
||||
export function parseLabelsArgument(parser: CommandParser, labels?: Labels) {
|
||||
if (labels) {
|
||||
args.push('LABELS');
|
||||
parser.push('LABELS');
|
||||
|
||||
for (const [label, value] of Object.entries(labels)) {
|
||||
args.push(label, value);
|
||||
parser.push(label, value);
|
||||
}
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
export type SampleRawReply = TuplesReply<[timestamp: NumberReply, value: DoubleReply]>;
|
||||
@@ -269,12 +268,12 @@ export function resp3MapToValue<
|
||||
return reply as never;
|
||||
}
|
||||
|
||||
export function pushSelectedLabelsArguments(
|
||||
args: Array<RedisArgument>,
|
||||
export function parseSelectedLabelsArguments(
|
||||
parser: CommandParser,
|
||||
selectedLabels: RedisVariadicArgument
|
||||
) {
|
||||
args.push('SELECTED_LABELS');
|
||||
return pushVariadicArguments(args, selectedLabels);
|
||||
parser.push('SELECTED_LABELS');
|
||||
parser.pushVariadic(selectedLabels);
|
||||
}
|
||||
|
||||
export type RawLabelValue = BlobStringReply | NullReply;
|
||||
|
Reference in New Issue
Block a user