RENAMENX · Valkey

RENAMENX

Renames a key only when the target key name doesn’t exist.

Usage

RENAMENX key newkey

Description

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.

Reply

One of the following:

Complexity

O(1)

ACL Categories

@fast @keyspace @write

Examples

127.0.0.1:6379> SET mykey "Hello"
OK
127.0.0.1:6379> SET myotherkey "World"
OK
127.0.0.1:6379> RENAMENX mykey myotherkey
(integer) 0
127.0.0.1:6379> GET myotherkey
"World"

History

See also

COPY, DEL, DUMP, EXISTS, EXPIRE, EXPIREAT, EXPIRETIME, KEYS, MIGRATE, MOVE, OBJECT, OBJECT ENCODING, OBJECT FREQ, OBJECT HELP, OBJECT IDLETIME, OBJECT REFCOUNT, PERSIST, PEXPIRE, PEXPIREAT, PEXPIRETIME, PTTL, RANDOMKEY, RENAME, RESTORE, SCAN, SORT, SORT_RO, TOUCH, TTL, TYPE, UNLINK, WAIT, WAITAOF.