Skip to content

Commit 11bd5d2

Browse files
committed
fix bug + tests
zpopmax (and related) get messed up a by a vsc getter insertion. memory_stats was teting for strings, but inherent DoubleReply are now returned as numbers by default
1 parent f3013f1 commit 11bd5d2

File tree

4 files changed

+17
-22
lines changed

4 files changed

+17
-22
lines changed

packages/client/lib/commands/MEMORY_STATS.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ describe('MEMORY STATS', () => {
2424
assert.equal(typeof memoryStats['keys.count'], 'number');
2525
assert.equal(typeof memoryStats['keys.bytes-per-key'], 'number');
2626
assert.equal(typeof memoryStats['dataset.bytes'], 'number');
27-
assert.equal(typeof memoryStats['dataset.percentage'], 'string');
28-
assert.equal(typeof memoryStats['peak.percentage'], 'string');
27+
assert.equal(typeof memoryStats['dataset.percentage'], 'number');
28+
assert.equal(typeof memoryStats['peak.percentage'], 'number');
2929
assert.equal(typeof memoryStats['allocator.allocated'], 'number');
3030
assert.equal(typeof memoryStats['allocator.active'], 'number');
3131
assert.equal(typeof memoryStats['allocator.resident'], 'number');
32-
assert.equal(typeof memoryStats['allocator-fragmentation.ratio'], 'string');
32+
assert.equal(typeof memoryStats['allocator-fragmentation.ratio'], 'number', 'allocator-fragmentation.ratio');
3333
assert.equal(typeof memoryStats['allocator-fragmentation.bytes'], 'number');
34-
assert.equal(typeof memoryStats['allocator-rss.ratio'], 'string');
34+
assert.equal(typeof memoryStats['allocator-rss.ratio'], 'number', 'allocator-rss.ratio');
3535
assert.equal(typeof memoryStats['allocator-rss.bytes'], 'number');
36-
assert.equal(typeof memoryStats['rss-overhead.ratio'], 'string');
36+
assert.equal(typeof memoryStats['rss-overhead.ratio'], 'number', 'rss-overhead.ratio');
3737
assert.equal(typeof memoryStats['rss-overhead.bytes'], 'number');
38-
assert.equal(typeof memoryStats['fragmentation'], 'string');
38+
assert.equal(typeof memoryStats['fragmentation'], 'number', 'fragmentation');
3939
assert.equal(typeof memoryStats['fragmentation.bytes'], 'number');
4040

4141
if (testUtils.isVersionGreaterThan([7])) {

packages/client/lib/commands/MEMORY_STATS.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export type MemoryStatsReply = TuplesToMapReply<[
1414
[BlobStringReply<'lua.caches'>, NumberReply],
1515
/** added in 7.0 */
1616
[BlobStringReply<'functions.caches'>, NumberReply],
17+
// FIXME: 'db.0', and perhaps others' is here and is a map that should be handled?
1718
[BlobStringReply<'overhead.total'>, NumberReply],
1819
[BlobStringReply<'keys.count'>, NumberReply],
1920
[BlobStringReply<'keys.bytes-per-key'>, NumberReply],
@@ -45,13 +46,13 @@ export default {
4546

4647
let i = 0;
4748
while (i < rawReply.length) {
48-
switch(i) {
49-
case 28:
50-
case 30:
51-
case 38:
52-
case 42:
53-
case 46:
54-
case 50:
49+
switch(rawReply[i].toString()) {
50+
case 'dataset.percentage':
51+
case 'peak.percentage':
52+
case 'allocator-fragmentation.ratio':
53+
case 'allocator-rss.ratio':
54+
case 'rss-overhead.ratio':
55+
case 'fragmentation':
5556
reply[rawReply[i++] as any] = transformDoubleReply[2](rawReply[i++] as unknown as BlobStringReply, preserve, typeMapping);
5657
break;
5758
default:
@@ -60,7 +61,7 @@ export default {
6061

6162
}
6263

63-
return reply as MemoryStatsReply['DEFAULT'];
64+
return reply as MemoryStatsReply;
6465
},
6566
3: undefined as unknown as () => MemoryStatsReply
6667
}

packages/client/lib/commands/ZPOPMAX.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,7 @@ export default {
1313

1414
return {
1515
value: reply[0],
16-
_score: transformDoubleReply[2](reply[1], preserve, typeMapping),
17-
get score() {
18-
return this._score;
19-
},
20-
set score(value) {
21-
this._score = value;
22-
},
16+
score: transformDoubleReply[2](reply[1], preserve, typeMapping),
2317
};
2418
},
2519
3: (reply: UnwrapReply<TuplesReply<[] | [BlobStringReply, DoubleReply]>>) => {

packages/client/lib/commands/generic-transformers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export const transformDoubleReply = {
5151
return reply as unknown as DoubleReply;
5252
}
5353
default: {
54-
let ret: Number;
54+
let ret: number;
5555

5656
switch (reply.toString()) {
5757
case 'inf':

0 commit comments

Comments
 (0)