{
  "schema_version": 2,
  "id": "commands/xlen",
  "title": "XLEN",
  "url": "https://redis.io/docs/latest/commands/xlen/",
  "summary": "Return the number of messages in a stream.",
  "since": "5.0.0",
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-09-18T16:45:25+01:00",
  "page_type": "content",
  "content_hash": "5fac269a68310ed7c22037afd1cc2bc15d852b147be996f42b18ab4720ee88da",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "Returns the number of entries inside a stream. If the specified key does not\nexist the command returns zero, as if the stream was empty.\nHowever note that unlike other Redis types, zero-length streams are\npossible, so you should call [`TYPE`](https://redis.io/docs/latest/commands/type) or [`EXISTS`](https://redis.io/docs/latest/commands/exists) in order to check if\na key exists or not.\n\nStreams are not auto-deleted once they have no entries inside (for instance\nafter an [`XDEL`](https://redis.io/docs/latest/commands/xdel) call), because the stream may have consumer groups\nassociated with it."
    },
    {
      "id": "required-arguments",
      "title": "Required arguments",
      "role": "content",
      "text": "<details open><summary><code>key</code></summary>\n\nThe stream key.\n\n</details>"
    },
    {
      "id": "examples",
      "title": "Examples",
      "role": "example",
      "text": "redis> XADD mystream * item 1\n\"1784722083902-0\"\nredis> XADD mystream * item 2\n\"1784722083903-0\"\nredis> XADD mystream * item 3\n\"1784722083904-0\"\nredis> XLEN mystream\n(integer) 3"
    },
    {
      "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> |  |"
    },
    {
      "id": "return-information",
      "title": "Return information",
      "role": "returns",
      "text": "**RESP2:**\n\n[Integer reply](../../develop/reference/protocol-spec#integers): the number of entries of the stream at _key_.\n\n**RESP3:**\n\n[Integer reply](../../develop/reference/protocol-spec#integers): the number of entries of the stream at _key_."
    }
  ],
  "examples": []
}
