diff --git a/packages/time-series/lib/commands/INFO.ts b/packages/time-series/lib/commands/INFO.ts index e7953ef568..8d8142ccdc 100644 --- a/packages/time-series/lib/commands/INFO.ts +++ b/packages/time-series/lib/commands/INFO.ts @@ -3,7 +3,17 @@ import { TimeSeriesDuplicatePolicies } from "."; import { TimeSeriesAggregationType } from "./CREATERULE"; import { transformDoubleReply } from '@redis/client/dist/lib/commands/generic-transformers'; -export type InfoRawReply = [ +export type InfoRawReplyTypes = SimpleStringReply | + NumberReply | + TimeSeriesDuplicatePolicies | null | + Array<[name: BlobStringReply, value: BlobStringReply]> | + BlobStringReply | + Array<[key: BlobStringReply, timeBucket: NumberReply, aggregationType: TimeSeriesAggregationType]> | + DoubleReply + +export type InfoRawReply = Array; + +export type InfoRawReplyOld = [ 'totalSamples', NumberReply, 'memoryUsage', @@ -54,8 +64,9 @@ export interface InfoReply { timeBucket: NumberReply; aggregationType: TimeSeriesAggregationType }>; - ignoreMaxTimeDiff: NumberReply; - ignoreMaxValDiff: DoubleReply; + /* Added in 7.4 */ + ignoreMaxTimeDiff: NumberReply | undefined; + ignoreMaxValDiff: DoubleReply | undefined; } export default { @@ -66,29 +77,41 @@ export default { }, transformReply: { 2: (reply: InfoRawReply, _, typeMapping?: TypeMapping): 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 - })), - ignoreMaxTimeDiff: reply[25], - ignoreMaxValDiff: transformDoubleReply[2](reply[27] as unknown as BlobStringReply, undefined, typeMapping) + const ret: InfoReply = { + totalSamples: reply[1] as NumberReply, + memoryUsage: reply[3] as NumberReply, + firstTimestamp: reply[5] as NumberReply, + lastTimestamp: reply[7] as NumberReply, + retentionTime: reply[9] as NumberReply, + chunkCount: reply[11] as NumberReply, + chunkSize: reply[13] as NumberReply, + chunkType: reply[15] as SimpleStringReply, + duplicatePolicy: reply[17] as TimeSeriesDuplicatePolicies | null, + labels: (reply[19] as Array<[name: BlobStringReply, value: BlobStringReply]>).map( + ([name, value]) => ({ + name, + value + }) + ), + sourceKey: reply[21] as BlobStringReply | null, + rules: (reply[23] as Array<[key: BlobStringReply, timeBucket: NumberReply, aggregationType: TimeSeriesAggregationType]>).map( + ([key, timeBucket, aggregationType]) => ({ + key, + timeBucket, + aggregationType + }) + ), + ignoreMaxTimeDiff: undefined, + ignoreMaxValDiff: undefined }; + + if (reply[24] != null && reply[24].toString() == 'ignoreMaxTimeDiff') { + // > 7.4 + ret.ignoreMaxTimeDiff = reply[25] as NumberReply; + ret.ignoreMaxValDiff = transformDoubleReply[2](reply[27] as unknown as BlobStringReply, undefined, typeMapping) + } + + return ret; }, 3: undefined as unknown as () => InfoReply } diff --git a/packages/time-series/lib/commands/INFO_DEBUG.ts b/packages/time-series/lib/commands/INFO_DEBUG.ts index 97ed7d9d18..f39927bd67 100644 --- a/packages/time-series/lib/commands/INFO_DEBUG.ts +++ b/packages/time-series/lib/commands/INFO_DEBUG.ts @@ -1,25 +1,29 @@ import { BlobStringReply, Command, NumberReply, SimpleStringReply, TypeMapping } from "@redis/client/dist/lib/RESP/types"; -import INFO, { InfoRawReply, InfoReply } from "./INFO"; +import INFO, { InfoRawReply, InfoRawReplyTypes, InfoReply } from "./INFO"; + +type chunkType = Array<[ + 'startTimestamp', + NumberReply, + 'endTimestamp', + NumberReply, + 'samples', + NumberReply, + 'size', + NumberReply, + 'bytesPerSample', + SimpleStringReply +]>; type InfoDebugRawReply = [ ...InfoRawReply, 'keySelfName', BlobStringReply, 'chunks', - Array<[ - 'startTimestamp', - NumberReply, - 'endTimestamp', - NumberReply, - 'samples', - NumberReply, - 'size', - NumberReply, - 'bytesPerSample', - SimpleStringReply - ]> + chunkType ]; +export type InfoDebugRawReplyType = InfoRawReplyTypes | chunkType + export interface InfoDebugReply extends InfoReply { keySelfName: BlobStringReply, chunks: Array<{ @@ -41,16 +45,22 @@ export default { }, transformReply: { 2: (rawReply: InfoDebugRawReply, _, typeMapping?: TypeMapping): InfoDebugReply => { - const reply = INFO.transformReply[2](rawReply as unknown as InfoRawReply, _, typeMapping); - (reply as InfoDebugReply).keySelfName = rawReply[29]; - (reply as InfoDebugReply).chunks = rawReply[31].map(chunk => ({ - startTimestamp: chunk[1], - endTimestamp: chunk[3], - samples: chunk[5], - size: chunk[7], - bytesPerSample: chunk[9] - })); - return reply as InfoDebugReply; + const reply = INFO.transformReply[2](rawReply as unknown as InfoRawReply, _, typeMapping) as unknown as InfoDebugReply; + // decide if > 7.4 or < 7.4 + const debugBaseIndex = reply.ignoreMaxTimeDiff === undefined ? 25 : 29; + + reply.keySelfName = rawReply[debugBaseIndex] as BlobStringReply; + reply.chunks = (rawReply[debugBaseIndex+2] as chunkType).map( + chunk => ({ + startTimestamp: chunk[1], + endTimestamp: chunk[3], + samples: chunk[5], + size: chunk[7], + bytesPerSample: chunk[9] + }) + ); + + return reply; }, 3: undefined as unknown as () => InfoDebugReply }