# MEMORY STATS

> Report how the server's memory is used, split into data and overhead.

URL: https://docs.hotkv.com/commands/memory-stats/

```
MEMORY STATS
```

- Group: Server
- Complexity: O(N) where N is the number of client connections
- HotKV Cloud: all plans
- On-Premise: no license needed

`MEMORY STATS` breaks down the server's memory use. It shows the same numbers
as the `memory` section of [INFO](https://docs.hotkv.com/commands/info/index.md), named the way Redis's
`MEMORY STATS` names them, so tools that read Redis's reply work with
HotKV.

## Fields

| Field | Meaning |
| --- | --- |
| `peak.allocated` | Highest memory use since the server started. |
| `total.allocated` | Memory in use now (`used_memory`). |
| `startup.allocated` | Memory the server used right after starting. |
| `replication.backlog` | Memory held by the replication backlog. |
| `clients.normal` | Memory held by client connections' input and output buffers. |
| `aof.buffer` | Memory held by the append-only file buffer. |
| `lua.caches` | Memory held by cached [EVAL](https://docs.hotkv.com/commands/eval/index.md) scripts. |
| `functions.caches` | Memory held by function libraries. |
| `overhead.total` | The sum of the overheads above plus the startup memory. |
| `keys.count` | Keys in all databases. |
| `keys.bytes-per-key` | Memory in use, less startup memory, divided by the number of keys. |
| `dataset.bytes` | Memory in use less the overhead: what the data takes. |
| `dataset.percentage` | `dataset.bytes` as a percentage of memory in use less startup memory. |
| `peak.percentage` | Memory in use as a percentage of the peak. |
| `fragmentation` | Resident memory divided by memory in use. |
| `fragmentation.bytes` | Resident memory minus memory in use. |

For compatibility the reply also has `clients.slaves` and `cluster.links`
(always `0`), and `allocator.allocated`, `allocator.active`,
`allocator.resident`, `allocator-fragmentation.ratio`,
`allocator-fragmentation.bytes`, `allocator.rss-ratio`,
`allocator.rss-bytes`, `rss-overhead.ratio` and `rss-overhead.bytes`, which
repeat the totals above or read `1` and `0`.

## Return value

27 fields: a map in RESP3, a flat array of name and value pairs in RESP2.
Byte counts and counts are integers. Ratios and percentages are doubles in
RESP3 and bulk strings in RESP2.

## Examples

```
127.0.0.1:6379> MEMORY STATS
 1) "peak.allocated"
 2) (integer) 92345216
 3) "total.allocated"
 4) (integer) 88213504
 5) "startup.allocated"
 6) (integer) 2153472
 ...
23) "keys.count"
24) (integer) 120000
 ...
```

## Compatibility

Same field names and shape as Redis 7 for the fields listed. Redis's reply
also includes per-database overhead entries (`db.0` and so on), which HotKV
does not report.

## See also

[INFO](https://docs.hotkv.com/commands/info/index.md), [MEMORY DOCTOR](https://docs.hotkv.com/commands/memory-doctor/index.md),
[MEMORY USAGE](https://docs.hotkv.com/commands/memory-usage/index.md)