mirror of
https://github.com/fluencelabs/redis
synced 2025-03-19 17:10:50 +00:00
Merge pull request #5562 from soloestoy/memory-usage-more-accurate
MEMORY command: make USAGE more accurate
This commit is contained in:
commit
4c544394eb
13
src/object.c
13
src/object.c
@ -1285,8 +1285,6 @@ NULL
|
|||||||
*
|
*
|
||||||
* Usage: MEMORY usage <key> */
|
* Usage: MEMORY usage <key> */
|
||||||
void memoryCommand(client *c) {
|
void memoryCommand(client *c) {
|
||||||
robj *o;
|
|
||||||
|
|
||||||
if (!strcasecmp(c->argv[1]->ptr,"help") && c->argc == 2) {
|
if (!strcasecmp(c->argv[1]->ptr,"help") && c->argc == 2) {
|
||||||
const char *help[] = {
|
const char *help[] = {
|
||||||
"DOCTOR - Return memory problems reports.",
|
"DOCTOR - Return memory problems reports.",
|
||||||
@ -1298,6 +1296,7 @@ NULL
|
|||||||
};
|
};
|
||||||
addReplyHelp(c, help);
|
addReplyHelp(c, help);
|
||||||
} else if (!strcasecmp(c->argv[1]->ptr,"usage") && c->argc >= 3) {
|
} else if (!strcasecmp(c->argv[1]->ptr,"usage") && c->argc >= 3) {
|
||||||
|
dictEntry *de;
|
||||||
long long samples = OBJ_COMPUTE_SIZE_DEF_SAMPLES;
|
long long samples = OBJ_COMPUTE_SIZE_DEF_SAMPLES;
|
||||||
for (int j = 3; j < c->argc; j++) {
|
for (int j = 3; j < c->argc; j++) {
|
||||||
if (!strcasecmp(c->argv[j]->ptr,"samples") &&
|
if (!strcasecmp(c->argv[j]->ptr,"samples") &&
|
||||||
@ -1316,10 +1315,12 @@ NULL
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((o = objectCommandLookupOrReply(c,c->argv[2],shared.nullbulk))
|
if ((de = dictFind(c->db->dict,c->argv[2]->ptr)) == NULL) {
|
||||||
== NULL) return;
|
addReply(c, shared.nullbulk);
|
||||||
size_t usage = objectComputeSize(o,samples);
|
return;
|
||||||
usage += sdsAllocSize(c->argv[2]->ptr);
|
}
|
||||||
|
size_t usage = objectComputeSize(dictGetVal(de),samples);
|
||||||
|
usage += sdsAllocSize(dictGetKey(de));
|
||||||
usage += sizeof(dictEntry);
|
usage += sizeof(dictEntry);
|
||||||
addReplyLongLong(c,usage);
|
addReplyLongLong(c,usage);
|
||||||
} else if (!strcasecmp(c->argv[1]->ptr,"stats") && c->argc == 2) {
|
} else if (!strcasecmp(c->argv[1]->ptr,"stats") && c->argc == 2) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user