Skip to content

Ask the HotKV docs

Answers come only from these docs and can be wrong; check the linked pages before you rely on them.

RENAMENX

Last updated
RENAMENX key newkey
Group
Keys
Complexity
O(1)
Arity
3 (exactly, counting the command name)
Flags
write, fast
Keys
first 1, last 2, step 1
HotKV Cloud
All plans
On-Premise
no license needed

RENAMENX renames key to newkey only when newkey does not exist. The value keeps its time to live. Renaming a key to its own name is treated as “the name is taken” and replies 0.

In a cluster, key and newkey must hash to the same slot.

Case RESP2 RESP3
Renamed Integer 1 Integer 1
newkey already exists Integer 0 Integer 0
key does not exist Error ERR no such key Error
127.0.0.1:6379> MSET a "first" b "second"
OK
127.0.0.1:6379> RENAMENX a b
(integer) 0
127.0.0.1:6379> RENAMENX a c
(integer) 1
127.0.0.1:6379> GET c
"first"

Same as Redis 7 and Valkey 8.

RENAME, COPY