You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
V5 bringing RESP3, Sentinel and TypeMapping to node-redis
RESP3 Support - Some commands responses in RESP3 aren't stable yet and therefore return an "untyped" ReplyUnion. Sentinel TypeMapping Correctly types Multi commands Note: some API changes to be further documented in v4-to-v5.md
This commit is contained in:
@@ -1,82 +1,128 @@
|
||||
import { TimeSeriesAggregationType, TimeSeriesDuplicatePolicies } from '.';
|
||||
import { ArrayReply, BlobStringReply, Command, DoubleReply, NumberReply, ReplyUnion, SimpleStringReply, TypeMapping } from "@redis/client/lib/RESP/types";
|
||||
import { TimeSeriesDuplicatePolicies } from ".";
|
||||
import { TimeSeriesAggregationType } from "./CREATERULE";
|
||||
import { transformDoubleReply } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
export type InfoRawReplyTypes = SimpleStringReply |
|
||||
NumberReply |
|
||||
TimeSeriesDuplicatePolicies | null |
|
||||
Array<[name: BlobStringReply, value: BlobStringReply]> |
|
||||
BlobStringReply |
|
||||
Array<[key: BlobStringReply, timeBucket: NumberReply, aggregationType: TimeSeriesAggregationType]> |
|
||||
DoubleReply
|
||||
|
||||
export const IS_READ_ONLY = true;
|
||||
export type InfoRawReply = Array<InfoRawReplyTypes>;
|
||||
|
||||
export function transformArguments(key: string): Array<string> {
|
||||
return ['TS.INFO', key];
|
||||
}
|
||||
|
||||
export type InfoRawReply = [
|
||||
'totalSamples',
|
||||
number,
|
||||
'memoryUsage',
|
||||
number,
|
||||
'firstTimestamp',
|
||||
number,
|
||||
'lastTimestamp',
|
||||
number,
|
||||
'retentionTime',
|
||||
number,
|
||||
'chunkCount',
|
||||
number,
|
||||
'chunkSize',
|
||||
number,
|
||||
'chunkType',
|
||||
string,
|
||||
'duplicatePolicy',
|
||||
TimeSeriesDuplicatePolicies | null,
|
||||
'labels',
|
||||
Array<[name: string, value: string]>,
|
||||
'sourceKey',
|
||||
string | null,
|
||||
'rules',
|
||||
Array<[key: string, timeBucket: number, aggregationType: TimeSeriesAggregationType]>
|
||||
export type InfoRawReplyOld = [
|
||||
'totalSamples',
|
||||
NumberReply,
|
||||
'memoryUsage',
|
||||
NumberReply,
|
||||
'firstTimestamp',
|
||||
NumberReply,
|
||||
'lastTimestamp',
|
||||
NumberReply,
|
||||
'retentionTime',
|
||||
NumberReply,
|
||||
'chunkCount',
|
||||
NumberReply,
|
||||
'chunkSize',
|
||||
NumberReply,
|
||||
'chunkType',
|
||||
SimpleStringReply,
|
||||
'duplicatePolicy',
|
||||
TimeSeriesDuplicatePolicies | null,
|
||||
'labels',
|
||||
ArrayReply<[name: BlobStringReply, value: BlobStringReply]>,
|
||||
'sourceKey',
|
||||
BlobStringReply | null,
|
||||
'rules',
|
||||
ArrayReply<[key: BlobStringReply, timeBucket: NumberReply, aggregationType: TimeSeriesAggregationType]>,
|
||||
'ignoreMaxTimeDiff',
|
||||
NumberReply,
|
||||
'ignoreMaxValDiff',
|
||||
DoubleReply,
|
||||
];
|
||||
|
||||
export interface InfoReply {
|
||||
totalSamples: number;
|
||||
memoryUsage: number;
|
||||
firstTimestamp: number;
|
||||
lastTimestamp: number;
|
||||
retentionTime: number;
|
||||
chunkCount: number;
|
||||
chunkSize: number;
|
||||
chunkType: string;
|
||||
duplicatePolicy: TimeSeriesDuplicatePolicies | null;
|
||||
labels: Array<{
|
||||
name: string;
|
||||
value: string;
|
||||
}>;
|
||||
sourceKey: string | null;
|
||||
rules: Array<{
|
||||
key: string;
|
||||
timeBucket: number;
|
||||
aggregationType: TimeSeriesAggregationType
|
||||
}>;
|
||||
totalSamples: NumberReply;
|
||||
memoryUsage: NumberReply;
|
||||
firstTimestamp: NumberReply;
|
||||
lastTimestamp: NumberReply;
|
||||
retentionTime: NumberReply;
|
||||
chunkCount: NumberReply;
|
||||
chunkSize: NumberReply;
|
||||
chunkType: SimpleStringReply;
|
||||
duplicatePolicy: TimeSeriesDuplicatePolicies | null;
|
||||
labels: Array<{
|
||||
name: BlobStringReply;
|
||||
value: BlobStringReply;
|
||||
}>;
|
||||
sourceKey: BlobStringReply | null;
|
||||
rules: Array<{
|
||||
key: BlobStringReply;
|
||||
timeBucket: NumberReply;
|
||||
aggregationType: TimeSeriesAggregationType
|
||||
}>;
|
||||
/** Added in 7.4 */
|
||||
ignoreMaxTimeDiff: NumberReply;
|
||||
/** Added in 7.4 */
|
||||
ignoreMaxValDiff: DoubleReply;
|
||||
}
|
||||
|
||||
export function transformReply(reply: InfoRawReply): InfoReply {
|
||||
return {
|
||||
totalSamples: reply[1],
|
||||
memoryUsage: reply[3],
|
||||
firstTimestamp: reply[5],
|
||||
lastTimestamp: reply[7],
|
||||
retentionTime: reply[9],
|
||||
chunkCount: reply[11],
|
||||
chunkSize: reply[13],
|
||||
chunkType: reply[15],
|
||||
duplicatePolicy: reply[17],
|
||||
labels: reply[19].map(([name, value]) => ({
|
||||
name,
|
||||
value
|
||||
})),
|
||||
sourceKey: reply[21],
|
||||
rules: reply[23].map(([key, timeBucket, aggregationType]) => ({
|
||||
key,
|
||||
timeBucket,
|
||||
aggregationType
|
||||
}))
|
||||
};
|
||||
}
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(key: string) {
|
||||
return ['TS.INFO', key];
|
||||
},
|
||||
transformReply: {
|
||||
2: (reply: InfoRawReply, _, typeMapping?: TypeMapping): InfoReply => {
|
||||
const ret = {} as any;
|
||||
|
||||
for (let i=0; i < reply.length; i += 2) {
|
||||
const key = (reply[i] as any).toString();
|
||||
|
||||
switch (key) {
|
||||
case 'totalSamples':
|
||||
case 'memoryUsage':
|
||||
case 'firstTimestamp':
|
||||
case 'lastTimestamp':
|
||||
case 'retentionTime':
|
||||
case 'chunkCount':
|
||||
case 'chunkSize':
|
||||
case 'chunkType':
|
||||
case 'duplicatePolicy':
|
||||
case 'sourceKey':
|
||||
case 'ignoreMaxTimeDiff':
|
||||
ret[key] = reply[i+1];
|
||||
break;
|
||||
case 'labels':
|
||||
ret[key] = (reply[i+1] as Array<[name: BlobStringReply, value: BlobStringReply]>).map(
|
||||
([name, value]) => ({
|
||||
name,
|
||||
value
|
||||
})
|
||||
);
|
||||
break;
|
||||
case 'rules':
|
||||
ret[key] = (reply[i+1] as Array<[key: BlobStringReply, timeBucket: NumberReply, aggregationType: TimeSeriesAggregationType]>).map(
|
||||
([key, timeBucket, aggregationType]) => ({
|
||||
key,
|
||||
timeBucket,
|
||||
aggregationType
|
||||
})
|
||||
);
|
||||
break;
|
||||
case 'ignoreMaxValDiff':
|
||||
ret[key] = transformDoubleReply[2](reply[27] as unknown as BlobStringReply, undefined, typeMapping);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
},
|
||||
3: undefined as unknown as () => ReplyUnion
|
||||
},
|
||||
unstableResp3: true
|
||||
} as const satisfies Command;
|
Reference in New Issue
Block a user