You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
68 lines
1.6 KiB
TypeScript
68 lines
1.6 KiB
TypeScript
import { RedisArgument, Command, CommandArguments } from '@redis/client/dist/lib/RESP/types';
|
|
import { RedisVariadicArgument } from '@redis/client/dist/lib/commands/generic-transformers';
|
|
import { Timestamp } from '.';
|
|
import { TsRangeOptions, pushRangeArguments } from './RANGE';
|
|
import { pushFilterArgument } from './MGET';
|
|
|
|
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 type TimeSeriesReducers = typeof TIME_SERIES_REDUCERS[keyof typeof TIME_SERIES_REDUCERS];
|
|
|
|
export interface TsMRangeOptions extends TsRangeOptions {
|
|
GROUPBY?: {
|
|
label: RedisArgument;
|
|
reducer: TimeSeriesReducers;
|
|
};
|
|
}
|
|
|
|
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
|
|
transformReply: undefined as unknown as () => any
|
|
} as const satisfies Command;
|