MEMORY USAGE key [SAMPLES count]

Available since 4.0.0.

Time complexity: O(N) where N is the number of samples.

The MEMORY USAGE command reports the number of bytes that a key and its value require to be stored in RAM.

The reported usage is the total of memory allocations for data and administrative overheads that a key its value require.

For nested data types, the optional SAMPLES option can be provided, where count is the number of sampled nested values. By default, this option is set to 5. To sample the all of the nested values, use SAMPLES 0.

*Examples

With Redis v4.0.1 64-bit and jemalloc, the empty string measures as follows:

  1. > SET "" ""
  2. OK
  3. > MEMORY USAGE ""
  4. (integer) 51

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. Longer keys and values show asymptotically linear usage.

  1. > SET foo bar
  2. OK
  3. > MEMORY USAGE foo
  4. (integer) 54
  5. > SET cento 01234567890123456789012345678901234567890123
  6. 45678901234567890123456789012345678901234567890123456789
  7. OK
  8. 127.0.0.1:6379> MEMORY USAGE cento
  9. (integer) 153

*Return value

Integer reply: the memory usage in bytes