{
  "schema_version": 2,
  "id": "commands/renamenx",
  "title": "RENAMENX",
  "url": "https://redis.io/docs/latest/commands/renamenx/",
  "summary": "Renames a key only when the target key name doesn't exist.",
  "since": "1.0.0",
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-09-18T09:48:32+01:00",
  "page_type": "content",
  "content_hash": "9f56b96273c5eee8a30a460a568a5ba77ba9ecb855469c35db079b58a30d7e15",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "> [!NOTE]\n> This command's behavior varies in clustered Redis environments. See the [multi-key operations](https://redis.io/docs/latest/develop/using-commands/multi-key-operations) page for more information.\n\n\nRenames `key` to `newkey` if `newkey` does not yet exist.\nIt returns an error when `key` does not exist.\n\nIn Cluster mode, both `key` and `newkey` must be in the same **hash slot**, meaning that in practice only keys that have the same hash tag can be reliably renamed in cluster."
    },
    {
      "id": "required-arguments",
      "title": "Required arguments",
      "role": "content",
      "text": "<details open><summary><code>key</code></summary>\n\nThe key to rename.\n\n</details>\n\n<details open><summary><code>newkey</code></summary>\n\nThe new key name. The command fails if a key with this name already exists.\n\n</details>"
    },
    {
      "id": "examples",
      "title": "Examples",
      "role": "example",
      "text": "redis> SET mykey \"Hello\"\nOK\nredis> SET myotherkey \"World\"\nOK\nredis> RENAMENX mykey myotherkey\n(integer) 0\nredis> GET myotherkey\n\"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> | For Active-Active or clustered databases, the original key and new key must be in the same hash slot. |"
    },
    {
      "id": "return-information",
      "title": "Return information",
      "role": "returns",
      "text": "**RESP2:**\n\nOne of the following:\n* [Integer reply](../../develop/reference/protocol-spec#integers): `1` if _key_ was renamed to _newkey_.\n* [Integer reply](../../develop/reference/protocol-spec#integers): `0` if _newkey_ already exists.\n\n**RESP3:**\n\nOne of the following:\n* [Integer reply](../../develop/reference/protocol-spec#integers): `1` if _key_ was renamed to _newkey_.\n* [Integer reply](../../develop/reference/protocol-spec#integers): `0` if _newkey_ already exists."
    }
  ],
  "examples": []
}
