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,21 +1,68 @@
|
||||
import { RedisCommandArguments } from '@redis/client/dist/lib/commands';
|
||||
import { MRangeOptions, Timestamp, pushMRangeArguments, Filter } from '.';
|
||||
import { RedisArgument, Command, CommandArguments } from '@redis/client/dist/lib/RESP/types';
|
||||
import { RedisVariadicArgument, pushVariadicArguments } from '@redis/client/dist/lib/commands/generic-transformers';
|
||||
import { Timestamp } from '.';
|
||||
import { TsRangeOptions, pushRangeArguments } from './RANGE';
|
||||
import { pushFilterArgument } from './MGET';
|
||||
|
||||
export const IS_READ_ONLY = true;
|
||||
export const TIME_SERIES_REDUCERS = {
|
||||
AVG: 'AVG',
|
||||
SUM: 'SUM',
|
||||
MIN: 'MIN',
|
||||
MAX: 'MAX',
|
||||
RANGE: 'RANGE',
|
||||
COUNT: 'COUNT',
|
||||
STD_P: 'STD.P',
|
||||
STD_S: 'STD.S',
|
||||
VAR_P: 'VAR.P',
|
||||
VAR_S: 'VAR.S'
|
||||
};
|
||||
|
||||
export function transformArguments(
|
||||
fromTimestamp: Timestamp,
|
||||
toTimestamp: Timestamp,
|
||||
filters: Filter,
|
||||
options?: MRangeOptions
|
||||
): RedisCommandArguments {
|
||||
return pushMRangeArguments(
|
||||
['TS.MRANGE'],
|
||||
fromTimestamp,
|
||||
toTimestamp,
|
||||
filters,
|
||||
options
|
||||
);
|
||||
export type TimeSeriesReducers = typeof TIME_SERIES_REDUCERS[keyof typeof TIME_SERIES_REDUCERS];
|
||||
|
||||
export interface TsMRangeOptions extends TsRangeOptions {
|
||||
GROUPBY?: {
|
||||
label: RedisArgument;
|
||||
reducer: TimeSeriesReducers;
|
||||
};
|
||||
}
|
||||
|
||||
export { transformMRangeReply as transformReply } from '.';
|
||||
export function pushGroupByArgument(args: CommandArguments, groupBy?: TsMRangeOptions['GROUPBY']) {
|
||||
if (groupBy) {
|
||||
args.push(
|
||||
'GROUPBY',
|
||||
groupBy.label,
|
||||
'REDUCE',
|
||||
groupBy.reducer
|
||||
);
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
export function transformMRangeArguments(
|
||||
command: RedisArgument,
|
||||
fromTimestamp: Timestamp,
|
||||
toTimestamp: Timestamp,
|
||||
filter: RedisVariadicArgument,
|
||||
options?: TsMRangeOptions
|
||||
) {
|
||||
let args = pushRangeArguments(
|
||||
[command],
|
||||
fromTimestamp,
|
||||
toTimestamp,
|
||||
options
|
||||
);
|
||||
|
||||
args = pushFilterArgument(args, filter);
|
||||
|
||||
return pushGroupByArgument(args, options?.GROUPBY);
|
||||
}
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: undefined,
|
||||
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;
|
||||
|
Reference in New Issue
Block a user