You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
WIP
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { RedisArgument, Command, CommandArguments } from '@redis/client/dist/lib/RESP/types';
|
||||
import { RedisVariadicArgument, pushVariadicArguments } from '@redis/client/dist/lib/commands/generic-transformers';
|
||||
import { RedisVariadicArgument } from '@redis/client/dist/lib/commands/generic-transformers';
|
||||
import { Timestamp } from '.';
|
||||
import { TsRangeOptions, pushRangeArguments } from './RANGE';
|
||||
import { pushFilterArgument } from './MGET';
|
||||
@@ -63,6 +63,5 @@ export default {
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments: transformMRangeArguments.bind(undefined, 'TS.MRANGE'),
|
||||
// TODO
|
||||
// export { transformMRangeReply as transformReply } from '.';
|
||||
transformReply: undefined as unknown as () => any
|
||||
} as const satisfies Command;
|
||||
|
@@ -27,6 +27,5 @@ export default {
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments: transformMRangeWithLabelsArguments.bind(undefined, 'TS.MRANGE'),
|
||||
// TODO
|
||||
// export { transformMRangeWithLabelsReply as transformReply } from '.';
|
||||
transformReply: undefined as unknown as () => any
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,11 +1,9 @@
|
||||
import { Command } from '@redis/client/dist/lib/RESP/types';
|
||||
import { transformMRangeWithLabelsArguments } from './MRANGE_WITHLABELS';
|
||||
import MRANGE_WITHLABELS, { transformMRangeWithLabelsArguments } from './MRANGE_WITHLABELS';
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: undefined,
|
||||
IS_READ_ONLY: true,
|
||||
FIRST_KEY_INDEX: MRANGE_WITHLABELS.FIRST_KEY_INDEX,
|
||||
IS_READ_ONLY: MRANGE_WITHLABELS.IS_READ_ONLY,
|
||||
transformArguments: transformMRangeWithLabelsArguments.bind(undefined, 'TS.MREVRANGE'),
|
||||
// TODO
|
||||
// export { transformMRangeWithLabelsReply as transformReply } from '.';
|
||||
transformReply: undefined as unknown as () => any
|
||||
transformReply: MRANGE_WITHLABELS.transformReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { CommandArguments, RedisArgument, Command } from '@redis/client/dist/lib/RESP/types';
|
||||
import { Timestamp, transformTimestampArgument } from '.';
|
||||
import { CommandArguments, RedisArgument, ArrayReply, UnwrapReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||
import { Timestamp, transformTimestampArgument, SampleRawReply, transformSampleReply } from '.';
|
||||
import { TimeSeriesAggregationType } from './CREATERULE';
|
||||
|
||||
export const TIME_SERIES_BUCKET_TIMESTAMP = {
|
||||
@@ -107,11 +107,13 @@ export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments: transformRangeArguments.bind(undefined, 'TS.RANGE'),
|
||||
// TODO
|
||||
// import { SampleReply, transformRangeReply } from '.';
|
||||
// export function transformReply(reply: Array<SampleRawReply>): Array<SampleReply> {
|
||||
// return transformRangeReply(reply);
|
||||
// }
|
||||
transformReply: undefined as unknown as () => any
|
||||
transformReply: {
|
||||
2(reply: UnwrapReply<ArrayReply<SampleRawReply[2]>>) {
|
||||
return reply.map(sample => transformSampleReply['2'](sample));
|
||||
},
|
||||
3(reply: UnwrapReply<ArrayReply<SampleRawReply[3]>>) {
|
||||
return reply.map(sample => transformSampleReply['3'](sample));
|
||||
}
|
||||
}
|
||||
} as const satisfies Command;
|
||||
|
||||
|
@@ -1,94 +1,33 @@
|
||||
import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import { transformArguments } from './REVRANGE';
|
||||
import { TimeSeriesAggregationType } from '.';
|
||||
import REVRANGE from './REVRANGE';
|
||||
import { TIME_SERIES_AGGREGATION_TYPE } from '../index';
|
||||
|
||||
describe('TS.REVRANGE', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('without options', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', '-', '+'),
|
||||
['TS.REVRANGE', 'key', '-', '+']
|
||||
);
|
||||
});
|
||||
|
||||
it('with FILTER_BY_TS', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', '-', '+', {
|
||||
FILTER_BY_TS: [0]
|
||||
}),
|
||||
['TS.REVRANGE', 'key', '-', '+', 'FILTER_BY_TS', '0']
|
||||
);
|
||||
});
|
||||
|
||||
it('with FILTER_BY_VALUE', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', '-', '+', {
|
||||
FILTER_BY_VALUE: {
|
||||
min: 1,
|
||||
max: 2
|
||||
}
|
||||
}),
|
||||
['TS.REVRANGE', 'key', '-', '+', 'FILTER_BY_VALUE', '1', '2']
|
||||
);
|
||||
});
|
||||
|
||||
it('with COUNT', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', '-', '+', {
|
||||
COUNT: 1
|
||||
}),
|
||||
['TS.REVRANGE', 'key', '-', '+', 'COUNT', '1']
|
||||
);
|
||||
});
|
||||
|
||||
it('with ALIGN', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', '-', '+', {
|
||||
ALIGN: '-'
|
||||
}),
|
||||
['TS.REVRANGE', 'key', '-', '+', 'ALIGN', '-']
|
||||
);
|
||||
});
|
||||
|
||||
it('with AGGREGATION', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', '-', '+', {
|
||||
AGGREGATION: {
|
||||
type: TimeSeriesAggregationType.AVERAGE,
|
||||
timeBucket: 1
|
||||
}
|
||||
}),
|
||||
['TS.REVRANGE', 'key', '-', '+', 'AGGREGATION', 'AVG', '1']
|
||||
);
|
||||
});
|
||||
|
||||
it('with FILTER_BY_TS, FILTER_BY_VALUE, COUNT, ALIGN, AGGREGATION', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', '-', '+', {
|
||||
FILTER_BY_TS: [0],
|
||||
FILTER_BY_VALUE: {
|
||||
min: 1,
|
||||
max: 2
|
||||
},
|
||||
COUNT: 1,
|
||||
ALIGN: '-',
|
||||
AGGREGATION: {
|
||||
type: TimeSeriesAggregationType.AVERAGE,
|
||||
timeBucket: 1
|
||||
}
|
||||
}),
|
||||
[
|
||||
'TS.REVRANGE', 'key', '-', '+', 'FILTER_BY_TS', '0', 'FILTER_BY_VALUE',
|
||||
'1', '2', 'COUNT', '1', 'ALIGN', '-', 'AGGREGATION', 'AVG', '1'
|
||||
]
|
||||
);
|
||||
});
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
REVRANGE.transformArguments('key', '-', '+', {
|
||||
FILTER_BY_TS: [0],
|
||||
FILTER_BY_VALUE: {
|
||||
min: 1,
|
||||
max: 2
|
||||
},
|
||||
COUNT: 1,
|
||||
ALIGN: '-',
|
||||
AGGREGATION: {
|
||||
type: TIME_SERIES_AGGREGATION_TYPE.AVG,
|
||||
timeBucket: 1
|
||||
}
|
||||
}),
|
||||
[
|
||||
'TS.REVRANGE', 'key', '-', '+', 'FILTER_BY_TS', '0', 'FILTER_BY_VALUE',
|
||||
'1', '2', 'COUNT', '1', 'ALIGN', '-', 'AGGREGATION', 'AVG', '1'
|
||||
]
|
||||
);
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.ts.revRange', async client => {
|
||||
const [, , reply] = await Promise.all([
|
||||
client.ts.add('key', 0, 1),
|
||||
const [, reply] = await Promise.all([
|
||||
client.ts.add('key', 1, 2),
|
||||
client.ts.revRange('key', '-', '+')
|
||||
]);
|
||||
@@ -96,9 +35,6 @@ describe('TS.REVRANGE', () => {
|
||||
assert.deepEqual(reply, [{
|
||||
timestamp: 1,
|
||||
value: 2
|
||||
}, {
|
||||
timestamp: 0,
|
||||
value: 1
|
||||
}]);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
});
|
||||
|
@@ -137,27 +137,20 @@ export function pushLabelsArgument(args: Array<RedisArgument>, labels?: Labels)
|
||||
return args;
|
||||
}
|
||||
|
||||
// export type RawLabelsReply = ArrayReply<TuplesReply<[BlobStringReply, BlobStringReply]>>;
|
||||
|
||||
// export function transformLablesReply(reply: RawLabelsReply) {
|
||||
// const labels: Record<string, BlobStringReply> = {};
|
||||
|
||||
// for (const [key, value] of reply) {
|
||||
// labels[key.toString()] = value;
|
||||
// }
|
||||
|
||||
// return labels
|
||||
// }
|
||||
export type SampleRawReply = {
|
||||
2: TuplesReply<[timestamp: NumberReply, value: BlobStringReply]>;
|
||||
3: TuplesReply<[timestamp: NumberReply, value: DoubleReply]>;
|
||||
};
|
||||
|
||||
export const transformSampleReply = {
|
||||
2(reply: TuplesReply<[timestamp: NumberReply, value: BlobStringReply]>) {
|
||||
2(reply: SampleRawReply[2]) {
|
||||
const [timestamp, value] = reply as unknown as UnwrapReply<typeof reply>;
|
||||
return {
|
||||
timestamp,
|
||||
value: Number(value)
|
||||
};
|
||||
},
|
||||
3(reply: TuplesReply<[timestamp: NumberReply, value: DoubleReply]>) {
|
||||
3(reply: SampleRawReply[3]) {
|
||||
const [timestamp, value] = reply as unknown as UnwrapReply<typeof reply>;
|
||||
return {
|
||||
timestamp,
|
||||
@@ -166,136 +159,6 @@ export const transformSampleReply = {
|
||||
}
|
||||
};
|
||||
|
||||
// export enum TimeSeriesBucketTimestamp {
|
||||
// LOW = '-',
|
||||
// HIGH = '+',
|
||||
// MID = '~'
|
||||
// }
|
||||
|
||||
// export interface RangeOptions {
|
||||
// LATEST?: boolean;
|
||||
// FILTER_BY_TS?: Array<Timestamp>;
|
||||
// FILTER_BY_VALUE?: {
|
||||
// min: number;
|
||||
// max: number;
|
||||
// };
|
||||
// COUNT?: number;
|
||||
// ALIGN?: Timestamp;
|
||||
// AGGREGATION?: {
|
||||
// type: TimeSeriesAggregationType;
|
||||
// timeBucket: Timestamp;
|
||||
// BUCKETTIMESTAMP?: TimeSeriesBucketTimestamp;
|
||||
// EMPTY?: boolean;
|
||||
// };
|
||||
// }
|
||||
|
||||
// export function pushRangeArguments(
|
||||
// args: RedisCommandArguments,
|
||||
// fromTimestamp: Timestamp,
|
||||
// toTimestamp: Timestamp,
|
||||
// options?: RangeOptions
|
||||
// ): RedisCommandArguments {
|
||||
// args.push(
|
||||
// transformTimestampArgument(fromTimestamp),
|
||||
// transformTimestampArgument(toTimestamp)
|
||||
// );
|
||||
|
||||
// pushLatestArgument(args, options?.LATEST);
|
||||
|
||||
// if (options?.FILTER_BY_TS) {
|
||||
// args.push('FILTER_BY_TS');
|
||||
// for (const ts of options.FILTER_BY_TS) {
|
||||
// args.push(transformTimestampArgument(ts));
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (options?.FILTER_BY_VALUE) {
|
||||
// args.push(
|
||||
// 'FILTER_BY_VALUE',
|
||||
// options.FILTER_BY_VALUE.min.toString(),
|
||||
// options.FILTER_BY_VALUE.max.toString()
|
||||
// );
|
||||
// }
|
||||
|
||||
// if (options?.COUNT) {
|
||||
// args.push(
|
||||
// 'COUNT',
|
||||
// options.COUNT.toString()
|
||||
// );
|
||||
// }
|
||||
|
||||
// if (options?.ALIGN) {
|
||||
// args.push(
|
||||
// 'ALIGN',
|
||||
// transformTimestampArgument(options.ALIGN)
|
||||
// );
|
||||
// }
|
||||
|
||||
// if (options?.AGGREGATION) {
|
||||
// args.push(
|
||||
// 'AGGREGATION',
|
||||
// options.AGGREGATION.type,
|
||||
// transformTimestampArgument(options.AGGREGATION.timeBucket)
|
||||
// );
|
||||
|
||||
// if (options.AGGREGATION.BUCKETTIMESTAMP) {
|
||||
// args.push(
|
||||
// 'BUCKETTIMESTAMP',
|
||||
// options.AGGREGATION.BUCKETTIMESTAMP
|
||||
// );
|
||||
// }
|
||||
|
||||
// if (options.AGGREGATION.EMPTY) {
|
||||
// args.push('EMPTY');
|
||||
// }
|
||||
// }
|
||||
|
||||
// return args;
|
||||
// }
|
||||
|
||||
// interface MRangeGroupBy {
|
||||
// label: string;
|
||||
// reducer: TimeSeriesReducers;
|
||||
// }
|
||||
|
||||
// export function pushMRangeGroupByArguments(args: RedisCommandArguments, groupBy?: MRangeGroupBy): RedisCommandArguments {
|
||||
// if (groupBy) {
|
||||
// args.push(
|
||||
// 'GROUPBY',
|
||||
// groupBy.label,
|
||||
// 'REDUCE',
|
||||
// groupBy.reducer
|
||||
// );
|
||||
// }
|
||||
|
||||
// return args;
|
||||
// }
|
||||
|
||||
// export type Filter = string | Array<string>;
|
||||
|
||||
// export function pushFilterArgument(args: RedisCommandArguments, filter: string | Array<string>): RedisCommandArguments {
|
||||
// args.push('FILTER');
|
||||
// return pushVariadicArguments(args, filter);
|
||||
// }
|
||||
|
||||
// export interface MRangeOptions extends RangeOptions {
|
||||
// GROUPBY?: MRangeGroupBy;
|
||||
// }
|
||||
|
||||
// export function pushMRangeArguments(
|
||||
// args: RedisCommandArguments,
|
||||
// fromTimestamp: Timestamp,
|
||||
// toTimestamp: Timestamp,
|
||||
// filter: Filter,
|
||||
// options?: MRangeOptions
|
||||
// ): RedisCommandArguments {
|
||||
// args = pushRangeArguments(args, fromTimestamp, toTimestamp, options);
|
||||
// args = pushFilterArgument(args, filter);
|
||||
// return pushMRangeGroupByArguments(args, options?.GROUPBY);
|
||||
// }
|
||||
|
||||
// export type SelectedLabels = string | Array<string>;
|
||||
|
||||
export function pushWithLabelsArgument(args: CommandArguments, selectedLabels?: RedisVariadicArgument) {
|
||||
if (!selectedLabels) {
|
||||
args.push('WITHLABELS');
|
||||
@@ -305,65 +168,3 @@ export function pushWithLabelsArgument(args: CommandArguments, selectedLabels?:
|
||||
return pushVariadicArguments(args, selectedLabels);
|
||||
}
|
||||
}
|
||||
|
||||
// export interface MRangeWithLabelsOptions extends MRangeOptions {
|
||||
// SELECTED_LABELS?: SelectedLabels;
|
||||
// }
|
||||
|
||||
// export function pushMRangeWithLabelsArguments(
|
||||
// args: RedisCommandArguments,
|
||||
// fromTimestamp: Timestamp,
|
||||
// toTimestamp: Timestamp,
|
||||
// filter: Filter,
|
||||
// options?: MRangeWithLabelsOptions
|
||||
// ): RedisCommandArguments {
|
||||
// args = pushRangeArguments(args, fromTimestamp, toTimestamp, options);
|
||||
// args = pushWithLabelsArgument(args, options?.SELECTED_LABELS);
|
||||
// args = pushFilterArgument(args, filter);
|
||||
// return pushMRangeGroupByArguments(args, options?.GROUPBY);
|
||||
// }
|
||||
|
||||
// export function transformRangeReply(reply: Array<SampleRawReply>): Array<SampleReply> {
|
||||
// return reply.map(transformSampleReply);
|
||||
// }
|
||||
|
||||
// type MRangeRawReply = Array<[
|
||||
// key: string,
|
||||
// labels: RawLabels,
|
||||
// samples: Array<SampleRawReply>
|
||||
// ]>;
|
||||
|
||||
// interface MRangeReplyItem {
|
||||
// key: string;
|
||||
// samples: Array<SampleReply>;
|
||||
// }
|
||||
|
||||
// export function transformMRangeReply(reply: MRangeRawReply): Array<MRangeReplyItem> {
|
||||
// const args = [];
|
||||
|
||||
// for (const [key, _, sample] of reply) {
|
||||
// args.push({
|
||||
// key,
|
||||
// samples: sample.map(transformSampleReply)
|
||||
// });
|
||||
// }
|
||||
|
||||
// return args;
|
||||
// }
|
||||
// export interface MRangeWithLabelsReplyItem extends MRangeReplyItem {
|
||||
// labels: Labels;
|
||||
// }
|
||||
|
||||
// export function transformMRangeWithLabelsReply(reply: MRangeRawReply): Array<MRangeWithLabelsReplyItem> {
|
||||
// const args = [];
|
||||
|
||||
// for (const [key, labels, samples] of reply) {
|
||||
// args.push({
|
||||
// key,
|
||||
// labels: transformLablesReply(labels),
|
||||
// samples: samples.map(transformSampleReply)
|
||||
// });
|
||||
// }
|
||||
|
||||
// return args;
|
||||
// }
|
||||
|
Reference in New Issue
Block a user