Back to Redis

RENAMENX

content/commands/renamenx.md

latest1.7 KB
Original Source

{{< 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.

Examples

{{% redis-cli %}} SET mykey "Hello" SET myotherkey "World" RENAMENX mykey myotherkey GET myotherkey {{% /redis-cli %}}

Redis Software and Redis Cloud compatibility

| 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. |

Return information

{{< multitabs id="renamenx-return-info" tab1="RESP2" tab2="RESP3" >}}

One of the following:

-tab-sep-

One of the following:

{{< /multitabs >}}