{
  "id": "memory-usage",
  "title": "MEMORY USAGE",
  "url": "https://redis.io/docs/latest/commands/memory-usage/",
  "summary": "Estimates the memory usage of a key.",
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-07-02T11:31:07-05:00",
  "page_type": "content",
  "content_hash": "637b5782e621dffa920871119b56adc9e40f7977c3fda2fc5b39a12887bed7b1",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "The `MEMORY USAGE` command reports the number of bytes that a key and its value\nrequire to be stored in RAM.\n\nThe reported usage is the total of memory allocations for data and\nadministrative overheads that a key and its value require.\n\nFor nested data types, the optional `SAMPLES` option can be provided, where\n`count` is the number of sampled nested values. The samples are averaged to estimate the total size.\nBy default, this option is set to `5`. To sample the all of the nested values, use `SAMPLES 0`."
    },
    {
      "id": "required-arguments",
      "title": "Required arguments",
      "role": "content",
      "text": "<details open><summary><code>key</code></summary>\n\nThe key to report memory usage for.\n\n</details>"
    },
    {
      "id": "optional-arguments",
      "title": "Optional arguments",
      "role": "parameters",
      "text": "<details open><summary><code>SAMPLES count</code></summary>\n\nThe number of sampled nested values for aggregate types. `0` samples all of them; the default is 5.\n\n</details>"
    },
    {
      "id": "examples",
      "title": "Examples",
      "role": "example",
      "text": "With Redis v7.2.0 64-bit and **jemalloc**, the empty string measures as follows:\n\n[code example]\n\nThese bytes are pure overhead at the moment as no actual data is stored, and are\nused for maintaining the internal data structures of the server (include internal allocator fragmentation). Longer keys and\nvalues show asymptotically linear usage.\n\n[code example]"
    },
    {
      "id": "redis-software-and-redis-cloud-compatibility",
      "title": "Redis Software and Redis Cloud compatibility",
      "role": "content",
      "text": "| Redis<br />Software | Redis<br />Cloud | <span style=\"min-width: 9em; display: table-cell\">Notes</span> |\n|:----------------------|:-----------------|:------|\n|<span title=\"Supported\">&#x2705; Standard</span><br /><span title=\"Supported\"><nobr>&#x2705; Active-Active</nobr></span> | <span title=\"Supported\">&#x2705; Standard</span><br /><span title=\"Supported\"><nobr>&#x2705; Active-Active</nobr></span> | Not supported for [scripts](https://redis.io/docs/latest/develop/programmability) in Redis versions earlier than 7. |\n\nNote: key memory usage is different on Redis Software or Redis Cloud active-active databases than on non-active-active databases. This is because memory usage includes some amount of CRDB overhead."
    },
    {
      "id": "return-information",
      "title": "Return information",
      "role": "returns",
      "text": "**RESP2:**\n\nOne of the following:\n* [Integer reply](../../develop/reference/protocol-spec#integers): the memory usage in bytes.\n* [Nil reply](../../develop/reference/protocol-spec#bulk-strings): if the key does not exist.\n\n**RESP3:**\n\nOne of the following:\n* [Integer reply](../../develop/reference/protocol-spec#integers): the memory usage in bytes.\n* [Null reply](../../develop/reference/protocol-spec#nulls): if the key does not exist."
    }
  ],
  "examples": [
    {
      "id": "examples-ex0",
      "language": "plaintext",
      "code": "> SET \"\" \"\"\nOK\n> MEMORY USAGE \"\"\n(integer) 56",
      "section_id": "examples"
    },
    {
      "id": "examples-ex1",
      "language": "plaintext",
      "code": "> SET foo bar\nOK\n> MEMORY USAGE foo\n(integer) 56\n> SET foo2 mybar\nOK\n> MEMORY USAGE foo2\n(integer) 64\n> SET foo3 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789\nOK\n> MEMORY USAGE foo3\n(integer) 160",
      "section_id": "examples"
    }
  ]
}
