content/commands/renamenx.md
{{< note >}} This command's behavior varies in clustered Redis environments. See the [multi-key operations]({{< relref "/develop/using-commands/multi-key-operations" >}}) page for more information. {{< /note >}}
Renames key to newkey if newkey does not yet exist.
It returns an error when key does not exist.
In 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.
{{% redis-cli %}} SET mykey "Hello" SET myotherkey "World" RENAMENX mykey myotherkey GET myotherkey {{% /redis-cli %}}
| Redis Software | Redis Cloud | <span style="min-width: 9em; display: table-cell">Notes</span> | |:----------------------|:-----------------|:------| | <span title="Supported">✅ Standard</span> <span title="Supported"><nobr>✅ Active-Active</nobr></span> | <span title="Supported">✅ Standard</span> <span title="Supported"><nobr>✅ Active-Active</nobr></span> | For Active-Active or clustered databases, the original key and new key must be in the same hash slot. |
{{< multitabs id="renamenx-return-info" tab1="RESP2" tab2="RESP3" >}}
One of the following:
1 if key was renamed to newkey.0 if newkey already exists.-tab-sep-
One of the following:
1 if key was renamed to newkey.0 if newkey already exists.{{< /multitabs >}}