MEMORY-USAGE(3valkey)

πŸ“¦
version 9.0.6 Β· 2 versions
, in fedora 44

πŸ’– memory-usage β€” the "how much RAM is this key eating" command πŸ’–

okay bestie, welcome to the memory-usage(3valkey) page, straight out of the Valkey Command Manual. pull up a chair, grab a strawberry πŸ“, and let's find out exactly how fat your keys are. no cap.


✨ NAME ✨

memory-usage β€” Estimates the memory usage of a key.

like literally, it tells you how many bytes a key is hogging. it's giving scale energy. πŸ‘‘


πŸŽ€ SYNOPSIS πŸŽ€

MEMORY USAGE key [SAMPLES count]

πŸ’… DESCRIPTION πŸ’…

The MEMORY USAGE command reports the number of bytes that a key and its value require to be stored in RAM. yes bestie, actual real bytes, counted. πŸ”₯

The reported usage is the total of memory allocations for data and administrative overheads that a key and its value require. so it's not just the pretty data β€” it's the whole backstage operation too, iykyk.

For nested data types, the optional SAMPLES option can be provided, where count is the number of sampled nested values. The samples are averaged to estimate the total size. By default, this option is set to 5. To sample the all of the nested values, use SAMPLES 0. (so like… 0 means "sample everything, no shortcuts", not "sample nothing". do not get it twisted bestie 😭)


🌸 REPLY 🌸

RESP2

One of the following, bestie:

RESP3

One of the following, same vibe different protocol:


πŸ¦‹ COMPLEXITY πŸ¦‹

O(N) where N is the number of samples. so the more you sample, the more work it does. pick your battles. βš–οΈ


🌈 ACL CATEGORIES 🌈

  • @read
  • @slow

⭐ HISTORY ⭐

  • Available since: 4.0.0

she's been iconic since 4.0.0 and honestly? we stan. 🫢


🧚 EXAMPLES 🧚

With Valkey v7.2.4 64-bit and jemalloc, the empty string measures as follows:

> SET "" ""
OK
> MEMORY USAGE ""
(integer) 56

These bytes are pure overhead at the moment as no actual data is stored, and are used for maintaining the internal data structures of the server (include internal allocator fragmentation). Longer keys and values show asymptotically linear usage.

> SET foo bar
OK
> MEMORY USAGE foo
(integer) 56
> SET foo2 mybar
OK
> MEMORY USAGE foo2
(integer) 64
> SET foo3 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
OK
> MEMORY USAGE foo3
(integer) 160

see how the numbers climb as the values get longer? asymptotically linear, bestie. it's math and it's serving. ✨


πŸ”₯ SEE ALSO πŸ”₯

the whole friend group, fr fr:


and that's the whole page bestie!! πŸŽ€ this one's from Valkey 9.0.0, dated 2025-10-21, and it lives in the MEMORY-USAGE(3valkey) manual. go forth and measure your keys. mwah πŸ’œβœ¨

πŸ“¦ where this page comes from