You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-07 13:22:56 +03:00
some more commands
This commit is contained in:
@@ -1,93 +1,53 @@
|
||||
export function transformArguments(): Array<string> {
|
||||
return ['MEMORY', 'STATS'];
|
||||
}
|
||||
// import { TuplesToMapReply, BlobStringReply, NumberReply, DoubleReply, Command, Resp2Reply } from '../RESP/types';
|
||||
|
||||
interface MemoryStatsReply {
|
||||
peakAllocated: number;
|
||||
totalAllocated: number;
|
||||
startupAllocated: number;
|
||||
replicationBacklog: number;
|
||||
clientsReplicas: number;
|
||||
clientsNormal: number;
|
||||
aofBuffer: number;
|
||||
luaCaches: number;
|
||||
overheadTotal: number;
|
||||
keysCount: number;
|
||||
keysBytesPerKey: number;
|
||||
datasetBytes: number;
|
||||
datasetPercentage: number;
|
||||
peakPercentage: number;
|
||||
allocatorAllocated?: number,
|
||||
allocatorActive?: number;
|
||||
allocatorResident?: number;
|
||||
allocatorFragmentationRatio?: number;
|
||||
allocatorFragmentationBytes?: number;
|
||||
allocatorRssRatio?: number;
|
||||
allocatorRssBytes?: number;
|
||||
rssOverheadRatio?: number;
|
||||
rssOverheadBytes?: number;
|
||||
fragmentation?: number;
|
||||
fragmentationBytes: number;
|
||||
db: {
|
||||
[key: number]: {
|
||||
overheadHashtableMain: number;
|
||||
overheadHashtableExpires: number;
|
||||
};
|
||||
};
|
||||
}
|
||||
// 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],
|
||||
// [BlobStringReply<'cluster.links'>, NumberReply],
|
||||
// [BlobStringReply<'aof.buffer'>, NumberReply],
|
||||
// [BlobStringReply<'lua.caches'>, NumberReply],
|
||||
// [BlobStringReply<'functions.caches'>, NumberReply],
|
||||
// [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]
|
||||
// ]>;
|
||||
|
||||
const FIELDS_MAPPING = {
|
||||
'peak.allocated': 'peakAllocated',
|
||||
'total.allocated': 'totalAllocated',
|
||||
'startup.allocated': 'startupAllocated',
|
||||
'replication.backlog': 'replicationBacklog',
|
||||
'clients.slaves': 'clientsReplicas',
|
||||
'clients.normal': 'clientsNormal',
|
||||
'aof.buffer': 'aofBuffer',
|
||||
'lua.caches': 'luaCaches',
|
||||
'overhead.total': 'overheadTotal',
|
||||
'keys.count': 'keysCount',
|
||||
'keys.bytes-per-key': 'keysBytesPerKey',
|
||||
'dataset.bytes': 'datasetBytes',
|
||||
'dataset.percentage': 'datasetPercentage',
|
||||
'peak.percentage': 'peakPercentage',
|
||||
'allocator.allocated': 'allocatorAllocated',
|
||||
'allocator.active': 'allocatorActive',
|
||||
'allocator.resident': 'allocatorResident',
|
||||
'allocator-fragmentation.ratio': 'allocatorFragmentationRatio',
|
||||
'allocator-fragmentation.bytes': 'allocatorFragmentationBytes',
|
||||
'allocator-rss.ratio': 'allocatorRssRatio',
|
||||
'allocator-rss.bytes': 'allocatorRssBytes',
|
||||
'rss-overhead.ratio': 'rssOverheadRatio',
|
||||
'rss-overhead.bytes': 'rssOverheadBytes',
|
||||
'fragmentation': 'fragmentation',
|
||||
'fragmentation.bytes': 'fragmentationBytes'
|
||||
},
|
||||
DB_FIELDS_MAPPING = {
|
||||
'overhead.hashtable.main': 'overheadHashtableMain',
|
||||
'overhead.hashtable.expires': 'overheadHashtableExpires'
|
||||
};
|
||||
// export default {
|
||||
// FIRST_KEY_INDEX: undefined,
|
||||
// IS_READ_ONLY: true,
|
||||
// transformArguments() {
|
||||
// return ['MEMORY', 'STATS'];
|
||||
// },
|
||||
// transformReply: {
|
||||
// 2: (rawReply: Array<BlobStringReply | NumberReply>) => {
|
||||
// const reply: Partial<Resp2Reply<MemoryStatsReply['DEFAULT']>> = {};
|
||||
|
||||
export function transformReply(rawReply: Array<string | number | Array<string | number>>): MemoryStatsReply {
|
||||
const reply: any = {
|
||||
db: {}
|
||||
};
|
||||
// let i = 0;
|
||||
// while (i < rawReply.length) {
|
||||
// const key = rawReply[i++] as keyof MemoryStatsReply['DEFAULT'];
|
||||
// reply[key] = rawReply[i++] as any;
|
||||
// }
|
||||
|
||||
for (let i = 0; i < rawReply.length; i += 2) {
|
||||
const key = rawReply[i] as string;
|
||||
if (key.startsWith('db.')) {
|
||||
const dbTuples = rawReply[i + 1] as Array<string | number>,
|
||||
db: any = {};
|
||||
for (let j = 0; j < dbTuples.length; j += 2) {
|
||||
db[DB_FIELDS_MAPPING[dbTuples[j] as keyof typeof DB_FIELDS_MAPPING]] = dbTuples[j + 1];
|
||||
}
|
||||
|
||||
reply.db[key.substring(3)] = db;
|
||||
continue;
|
||||
}
|
||||
|
||||
reply[FIELDS_MAPPING[key as keyof typeof FIELDS_MAPPING]] = Number(rawReply[i + 1]);
|
||||
}
|
||||
|
||||
return reply as MemoryStatsReply;
|
||||
}
|
||||
// return reply as MemoryStatsReply['DEFAULT'];
|
||||
// },
|
||||
// 3: undefined as unknown as () => MemoryStatsReply
|
||||
// }
|
||||
// } as const satisfies Command;
|
||||
|
Reference in New Issue
Block a user