1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-09 00:22:08 +03:00
Files
node-redis/packages/client/lib/commands/MEMORY_STATS.ts
Shaya Potter b2d35c5286 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
2024-10-15 17:46:52 +03:00

69 lines
2.8 KiB
TypeScript

import { TuplesToMapReply, BlobStringReply, NumberReply, DoubleReply, ArrayReply, UnwrapReply, Command, TypeMapping } from '../RESP/types';
import { transformDoubleReply } from './generic-transformers';
export type MemoryStatsReply = TuplesToMapReply<[
[BlobStringReply<'peak.allocated'>, NumberReply],
[BlobStringReply<'total.allocated'>, NumberReply],
[BlobStringReply<'startup.allocated'>, NumberReply],
[BlobStringReply<'replication.backlog'>, NumberReply],
[BlobStringReply<'clients.slaves'>, NumberReply],
[BlobStringReply<'clients.normal'>, NumberReply],
/** added in 7.0 */
[BlobStringReply<'cluster.links'>, NumberReply],
[BlobStringReply<'aof.buffer'>, NumberReply],
[BlobStringReply<'lua.caches'>, NumberReply],
/** added in 7.0 */
[BlobStringReply<'functions.caches'>, NumberReply],
// FIXME: 'db.0', and perhaps others' is here and is a map that should be handled?
[BlobStringReply<'overhead.total'>, NumberReply],
[BlobStringReply<'keys.count'>, NumberReply],
[BlobStringReply<'keys.bytes-per-key'>, NumberReply],
[BlobStringReply<'dataset.bytes'>, NumberReply],
[BlobStringReply<'dataset.percentage'>, DoubleReply],
[BlobStringReply<'peak.percentage'>, DoubleReply],
[BlobStringReply<'allocator.allocated'>, NumberReply],
[BlobStringReply<'allocator.active'>, NumberReply],
[BlobStringReply<'allocator.resident'>, NumberReply],
[BlobStringReply<'allocator-fragmentation.ratio'>, DoubleReply],
[BlobStringReply<'allocator-fragmentation.bytes'>, NumberReply],
[BlobStringReply<'allocator-rss.ratio'>, DoubleReply],
[BlobStringReply<'allocator-rss.bytes'>, NumberReply],
[BlobStringReply<'rss-overhead.ratio'>, DoubleReply],
[BlobStringReply<'rss-overhead.bytes'>, NumberReply],
[BlobStringReply<'fragmentation'>, DoubleReply],
[BlobStringReply<'fragmentation.bytes'>, NumberReply]
]>;
export default {
FIRST_KEY_INDEX: undefined,
IS_READ_ONLY: true,
transformArguments() {
return ['MEMORY', 'STATS'];
},
transformReply: {
2: (rawReply: UnwrapReply<ArrayReply<BlobStringReply | NumberReply>>, preserve?: any, typeMapping?: TypeMapping) => {
const reply: any = {};
let i = 0;
while (i < rawReply.length) {
switch(rawReply[i].toString()) {
case 'dataset.percentage':
case 'peak.percentage':
case 'allocator-fragmentation.ratio':
case 'allocator-rss.ratio':
case 'rss-overhead.ratio':
case 'fragmentation':
reply[rawReply[i++] as any] = transformDoubleReply[2](rawReply[i++] as unknown as BlobStringReply, preserve, typeMapping);
break;
default:
reply[rawReply[i++] as any] = rawReply[i++];
}
}
return reply as MemoryStatsReply;
},
3: undefined as unknown as () => MemoryStatsReply
}
} as const satisfies Command;