Skip to content

Commit 3f65936

Browse files
committed
attempt to make ts info / info debug backwards cmmpatable
1 parent 9e8c183 commit 3f65936

File tree

2 files changed

+81
-48
lines changed

2 files changed

+81
-48
lines changed

packages/time-series/lib/commands/INFO.ts

Lines changed: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,17 @@ import { TimeSeriesDuplicatePolicies } from ".";
33
import { TimeSeriesAggregationType } from "./CREATERULE";
44
import { transformDoubleReply } from '@redis/client/dist/lib/commands/generic-transformers';
55

6-
export type InfoRawReply = [
6+
export type InfoRawReplyTypes = SimpleStringReply |
7+
NumberReply |
8+
TimeSeriesDuplicatePolicies | null |
9+
Array<[name: BlobStringReply, value: BlobStringReply]> |
10+
BlobStringReply |
11+
Array<[key: BlobStringReply, timeBucket: NumberReply, aggregationType: TimeSeriesAggregationType]> |
12+
DoubleReply
13+
14+
export type InfoRawReply = Array<InfoRawReplyTypes>;
15+
16+
export type InfoRawReplyOld = [
717
'totalSamples',
818
NumberReply,
919
'memoryUsage',
@@ -54,8 +64,9 @@ export interface InfoReply {
5464
timeBucket: NumberReply;
5565
aggregationType: TimeSeriesAggregationType
5666
}>;
57-
ignoreMaxTimeDiff: NumberReply;
58-
ignoreMaxValDiff: DoubleReply;
67+
/* Added in 7.4 */
68+
ignoreMaxTimeDiff: NumberReply | undefined;
69+
ignoreMaxValDiff: DoubleReply | undefined;
5970
}
6071

6172
export default {
@@ -66,29 +77,41 @@ export default {
6677
},
6778
transformReply: {
6879
2: (reply: InfoRawReply, _, typeMapping?: TypeMapping): InfoReply => {
69-
return {
70-
totalSamples: reply[1],
71-
memoryUsage: reply[3],
72-
firstTimestamp: reply[5],
73-
lastTimestamp: reply[7],
74-
retentionTime: reply[9],
75-
chunkCount: reply[11],
76-
chunkSize: reply[13],
77-
chunkType: reply[15],
78-
duplicatePolicy: reply[17],
79-
labels: reply[19].map(([name, value]) => ({
80-
name,
81-
value
82-
})),
83-
sourceKey: reply[21],
84-
rules: reply[23].map(([key, timeBucket, aggregationType]) => ({
85-
key,
86-
timeBucket,
87-
aggregationType
88-
})),
89-
ignoreMaxTimeDiff: reply[25],
90-
ignoreMaxValDiff: transformDoubleReply[2](reply[27] as unknown as BlobStringReply, undefined, typeMapping)
80+
const ret: InfoReply = {
81+
totalSamples: reply[1] as NumberReply,
82+
memoryUsage: reply[3] as NumberReply,
83+
firstTimestamp: reply[5] as NumberReply,
84+
lastTimestamp: reply[7] as NumberReply,
85+
retentionTime: reply[9] as NumberReply,
86+
chunkCount: reply[11] as NumberReply,
87+
chunkSize: reply[13] as NumberReply,
88+
chunkType: reply[15] as SimpleStringReply,
89+
duplicatePolicy: reply[17] as TimeSeriesDuplicatePolicies | null,
90+
labels: (reply[19] as Array<[name: BlobStringReply, value: BlobStringReply]>).map(
91+
([name, value]) => ({
92+
name,
93+
value
94+
})
95+
),
96+
sourceKey: reply[21] as BlobStringReply | null,
97+
rules: (reply[23] as Array<[key: BlobStringReply, timeBucket: NumberReply, aggregationType: TimeSeriesAggregationType]>).map(
98+
([key, timeBucket, aggregationType]) => ({
99+
key,
100+
timeBucket,
101+
aggregationType
102+
})
103+
),
104+
ignoreMaxTimeDiff: undefined,
105+
ignoreMaxValDiff: undefined
91106
};
107+
108+
if (reply[24] != null && reply[24].toString() == 'ignoreMaxTimeDiff') {
109+
// > 7.4
110+
ret.ignoreMaxTimeDiff = reply[25] as NumberReply;
111+
ret.ignoreMaxValDiff = transformDoubleReply[2](reply[27] as unknown as BlobStringReply, undefined, typeMapping)
112+
}
113+
114+
return ret;
92115
},
93116
3: undefined as unknown as () => InfoReply
94117
}

packages/time-series/lib/commands/INFO_DEBUG.ts

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
11
import { BlobStringReply, Command, NumberReply, SimpleStringReply, TypeMapping } from "@redis/client/dist/lib/RESP/types";
2-
import INFO, { InfoRawReply, InfoReply } from "./INFO";
2+
import INFO, { InfoRawReply, InfoRawReplyTypes, InfoReply } from "./INFO";
3+
4+
type chunkType = Array<[
5+
'startTimestamp',
6+
NumberReply,
7+
'endTimestamp',
8+
NumberReply,
9+
'samples',
10+
NumberReply,
11+
'size',
12+
NumberReply,
13+
'bytesPerSample',
14+
SimpleStringReply
15+
]>;
316

417
type InfoDebugRawReply = [
518
...InfoRawReply,
619
'keySelfName',
720
BlobStringReply,
821
'chunks',
9-
Array<[
10-
'startTimestamp',
11-
NumberReply,
12-
'endTimestamp',
13-
NumberReply,
14-
'samples',
15-
NumberReply,
16-
'size',
17-
NumberReply,
18-
'bytesPerSample',
19-
SimpleStringReply
20-
]>
22+
chunkType
2123
];
2224

25+
export type InfoDebugRawReplyType = InfoRawReplyTypes | chunkType
26+
2327
export interface InfoDebugReply extends InfoReply {
2428
keySelfName: BlobStringReply,
2529
chunks: Array<{
@@ -41,16 +45,22 @@ export default {
4145
},
4246
transformReply: {
4347
2: (rawReply: InfoDebugRawReply, _, typeMapping?: TypeMapping): InfoDebugReply => {
44-
const reply = INFO.transformReply[2](rawReply as unknown as InfoRawReply, _, typeMapping);
45-
(reply as InfoDebugReply).keySelfName = rawReply[29];
46-
(reply as InfoDebugReply).chunks = rawReply[31].map(chunk => ({
47-
startTimestamp: chunk[1],
48-
endTimestamp: chunk[3],
49-
samples: chunk[5],
50-
size: chunk[7],
51-
bytesPerSample: chunk[9]
52-
}));
53-
return reply as InfoDebugReply;
48+
const reply = INFO.transformReply[2](rawReply as unknown as InfoRawReply, _, typeMapping) as unknown as InfoDebugReply;
49+
// decide if > 7.4 or < 7.4
50+
const debugBaseIndex = reply.ignoreMaxTimeDiff === undefined ? 25 : 29;
51+
52+
reply.keySelfName = rawReply[debugBaseIndex] as BlobStringReply;
53+
reply.chunks = (rawReply[debugBaseIndex+2] as chunkType).map(
54+
chunk => ({
55+
startTimestamp: chunk[1],
56+
endTimestamp: chunk[3],
57+
samples: chunk[5],
58+
size: chunk[7],
59+
bytesPerSample: chunk[9]
60+
})
61+
);
62+
63+
return reply;
5464
},
5565
3: undefined as unknown as () => InfoDebugReply
5666
}

0 commit comments

Comments
 (0)