{
  "schema_version": 2,
  "id": "commands/ltrim",
  "title": "LTRIM",
  "url": "https://redis.io/docs/latest/commands/ltrim/",
  "summary": "Removes elements from both ends a list. Deletes the list if all elements were trimmed.",
  "since": "1.0.0",
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-09-18T09:47:41+01:00",
  "page_type": "content",
  "content_hash": "27f1c3908f2f799583a9ceac3185963cc3d4edc6ee176b45fea640016711d85f",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "Trim an existing list so that it will contain only the specified range of\nelements specified.\nBoth `start` and `stop` are zero-based indexes, where `0` is the first element\nof the list (the head), `1` the next element, and so on.\n\nFor example: `LTRIM foobar 0 2` will modify the list stored at `foobar` so that\nonly the first three elements of the list will remain.\n\n`start` and `stop` can also be negative numbers indicating offsets from the end\nof the list, where `-1` is the last element of the list, `-2` the penultimate\nelement, and so on.\n\nOut of range indexes will not produce an error: if `start` is larger than the\nend of the list (`start > stop`), the result will be an empty list, which\ncauses `key` to be removed.\nIf `stop` is larger than the end of the list (`stop > start`), Redis will treat it like the last\nelement of the list."
    },
    {
      "id": "required-arguments",
      "title": "Required arguments",
      "role": "content",
      "text": "<details open><summary><code>key</code></summary>\n\nThe name of the key that holds the list.\n\n</details>\n\n<details open><summary><code>start</code></summary>\n\nThe zero-based start index. Negative indexes count from the tail.\n\n</details>\n\n<details open><summary><code>stop</code></summary>\n\nThe zero-based stop index (inclusive). Negative indexes count from the tail.\n\n</details>"
    },
    {
      "id": "examples",
      "title": "Examples",
      "role": "example",
      "text": "A common use of `LTRIM` is to use it with [`LPUSH`](https://redis.io/docs/latest/commands/lpush) or [`RPUSH`](https://redis.io/docs/latest/commands/rpush).\nFor example:\n\n[code example]\n\nThis pair of commands will push a new element on the list, while making sure\nthat the list will not grow larger than 100 elements.\nThis is very useful when using Redis to store logs for example.\nIt is important to note that when used in this way `LTRIM` is an O(1) operation\nbecause in the average case just one element is removed from the tail of the\nlist.\n\n\n\nredis> RPUSH mylist \"one\"\n(integer) 1\nredis> RPUSH mylist \"two\"\n(integer) 2\nredis> RPUSH mylist \"three\"\n(integer) 3\nredis> LTRIM mylist 1 -1\nOK\nredis> LRANGE mylist 0 -1\n1) \"two\"\n2) \"three\""
    },
    {
      "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[Simple string reply](../../develop/reference/protocol-spec#simple-strings): `OK`.\n\n**RESP3:**\n\n[Simple string reply](../../develop/reference/protocol-spec#simple-strings): `OK`."
    }
  ],
  "examples": [
    {
      "id": "examples-ex0",
      "language": "plaintext",
      "code": "LPUSH mylist someelement\nLTRIM mylist 0 99",
      "section_id": "examples"
    }
  ]
}
