Skip to content

Commit 25fdd32

Browse files
committed
fix ts.info/debug again to hopefully be cleaner
1 parent 31d61b8 commit 25fdd32

File tree

3 files changed

+77
-56
lines changed

3 files changed

+77
-56
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('TS.INFO', () => {
2323
client.ts.add('key', 1, 10)
2424
]);
2525

26-
assertInfo(await client.ts.info('key'));
26+
assertInfo(await client.ts.info('key') as any);
2727
}, GLOBAL.SERVERS.OPEN);
2828
});
2929

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

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BlobStringReply, Command, DoubleReply, NumberReply, SimpleStringReply, TypeMapping } from "@redis/client/dist/lib/RESP/types";
1+
import { ArrayReply, BlobStringReply, Command, DoubleReply, NumberReply, ReplyUnion, SimpleStringReply, TypeMapping } from "@redis/client/lib/RESP/types";
22
import { TimeSeriesDuplicatePolicies } from ".";
33
import { TimeSeriesAggregationType } from "./CREATERULE";
44
import { transformDoubleReply } from '@redis/client/dist/lib/commands/generic-transformers';
@@ -33,11 +33,11 @@ export type InfoRawReplyOld = [
3333
'duplicatePolicy',
3434
TimeSeriesDuplicatePolicies | null,
3535
'labels',
36-
Array<[name: BlobStringReply, value: BlobStringReply]>,
36+
ArrayReply<[name: BlobStringReply, value: BlobStringReply]>,
3737
'sourceKey',
3838
BlobStringReply | null,
3939
'rules',
40-
Array<[key: BlobStringReply, timeBucket: NumberReply, aggregationType: TimeSeriesAggregationType]>,
40+
ArrayReply<[key: BlobStringReply, timeBucket: NumberReply, aggregationType: TimeSeriesAggregationType]>,
4141
'ignoreMaxTimeDiff',
4242
NumberReply,
4343
'ignoreMaxValDiff',
@@ -77,42 +77,51 @@ export default {
7777
},
7878
transformReply: {
7979
2: (reply: InfoRawReply, _, typeMapping?: TypeMapping): InfoReply => {
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
106-
};
80+
const ret = {} as any;
10781

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)
82+
for (let i=0; i < reply.length; i += 2) {
83+
const key = (reply[i] as any).toString();
84+
85+
switch (key) {
86+
case 'totalSamples':
87+
case 'memoryUsage':
88+
case 'firstTimestamp':
89+
case 'lastTimestamp':
90+
case 'retentionTime':
91+
case 'chunkCount':
92+
case 'chunkSize':
93+
case 'chunkType':
94+
case 'duplicatePolicy':
95+
case 'sourceKey':
96+
case 'ignoreMaxTimeDiff':
97+
ret[key] = reply[i+1];
98+
break;
99+
case 'labels':
100+
ret[key] = (reply[i+1] as Array<[name: BlobStringReply, value: BlobStringReply]>).map(
101+
([name, value]) => ({
102+
name,
103+
value
104+
})
105+
)
106+
break;
107+
case 'rules':
108+
ret[key] = (reply[i+1] as Array<[key: BlobStringReply, timeBucket: NumberReply, aggregationType: TimeSeriesAggregationType]>).map(
109+
([key, timeBucket, aggregationType]) => ({
110+
key,
111+
timeBucket,
112+
aggregationType
113+
})
114+
)
115+
break;
116+
case 'ignoreMaxValDiff':
117+
ret[key] = transformDoubleReply[2](reply[27] as unknown as BlobStringReply, undefined, typeMapping)
118+
break;
119+
}
112120
}
113121

114122
return ret;
115123
},
116-
3: undefined as unknown as () => InfoReply
117-
}
124+
3: undefined as unknown as () => ReplyUnion
125+
},
126+
unstableResp3: true
118127
} as const satisfies Command;

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

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { BlobStringReply, Command, NumberReply, SimpleStringReply, TypeMapping } from "@redis/client/dist/lib/RESP/types";
22
import INFO, { InfoRawReply, InfoRawReplyTypes, InfoReply } from "./INFO";
3+
import { ReplyUnion } from '@redis/client/lib/RESP/types';
34

45
type chunkType = Array<[
56
'startTimestamp',
@@ -18,7 +19,7 @@ type InfoDebugRawReply = [
1819
...InfoRawReply,
1920
'keySelfName',
2021
BlobStringReply,
21-
'chunks',
22+
'Chunks',
2223
chunkType
2324
];
2425

@@ -44,24 +45,35 @@ export default {
4445
return args;
4546
},
4647
transformReply: {
47-
2: (rawReply: InfoDebugRawReply, _, typeMapping?: TypeMapping): 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;
48+
2: (reply: InfoDebugRawReply, _, typeMapping?: TypeMapping): InfoDebugReply => {
49+
const ret = INFO.transformReply[2](reply as unknown as InfoRawReply, _, typeMapping) as any;
5150

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-
);
51+
for (let i=0; i < reply.length; i += 2) {
52+
const key = (reply[i] as any).toString();
53+
54+
switch (key) {
55+
case 'keySelfName': {
56+
ret[key] = reply[i+1];
57+
break;
58+
}
59+
case 'Chunks': {
60+
ret['chunks'] = (reply[i+1] as chunkType).map(
61+
chunk => ({
62+
startTimestamp: chunk[1],
63+
endTimestamp: chunk[3],
64+
samples: chunk[5],
65+
size: chunk[7],
66+
bytesPerSample: chunk[9]
67+
})
68+
);
69+
break;
70+
}
71+
}
72+
}
6273

63-
return reply;
64-
},
65-
3: undefined as unknown as () => InfoDebugReply
66-
}
74+
return ret;
75+
},
76+
3: undefined as unknown as () => ReplyUnion
77+
},
78+
unstableResp3: true
6779
} as const satisfies Command;

0 commit comments

Comments
 (0)