{
  "schema_version": 2,
  "id": "commands/linsert",
  "title": "LINSERT",
  "url": "https://redis.io/docs/latest/commands/linsert/",
  "summary": "Inserts an element before or after another element in a list.",
  "since": "2.2.0",
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-07-24T11:07:00+02:00",
  "page_type": "content",
  "content_hash": "7f292070493efbfa637dc490fcdd170ff4823a1f60290f86f43010566ff66f33",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "Inserts `element` in the list stored at `key` either before or after the reference\nvalue `pivot`.\n\nWhen `key` does not exist, it is considered an empty list and no operation is\nperformed.\n\nAn error is returned when `key` exists but does not hold a list value."
    },
    {
      "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>BEFORE | AFTER</code></summary>\n\nWhether to insert `element` before or after `pivot`.\n\n</details>\n\n<details open><summary><code>pivot</code></summary>\n\nThe existing element to insert relative to.\n\n</details>\n\n<details open><summary><code>element</code></summary>\n\nThe value to insert.\n\n</details>"
    },
    {
      "id": "examples",
      "title": "Examples",
      "role": "example",
      "text": "redis> RPUSH mylist \"Hello\"\n(integer) 1\nredis> RPUSH mylist \"World\"\n(integer) 2\nredis> LINSERT mylist BEFORE \"World\" \"There\"\n(integer) 3\nredis> LRANGE mylist 0 -1\n1) \"Hello\"\n2) \"There\"\n3) \"World\""
    },
    {
      "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\nOne of the following:\n* [Integer reply](../../develop/reference/protocol-spec#integers): the list length after a successful insert operation.\n* [Integer reply](../../develop/reference/protocol-spec#integers): `0` when the key doesn't exist.\n* [Integer reply](../../develop/reference/protocol-spec#integers): `-1` when the pivot wasn't found.\n\n**RESP3:**\n\nOne of the following:\n* [Integer reply](../../develop/reference/protocol-spec#integers): the list length after a successful insert operation.\n* [Integer reply](../../develop/reference/protocol-spec#integers): `0` when the key doesn't exist.\n* [Integer reply](../../develop/reference/protocol-spec#integers): `-1` when the pivot wasn't found."
    }
  ],
  "examples": []
}
