RENAMENX(3valkey)
π RENAMENX β the glow-up your keys deserve (but only if the name's free)
okay bestie, welcome to the Valkey Command Manual, page RENAMENX(3valkey) πΈ this is the one you pull up when you want to rename a key but you're not about to steamroll some other key that already claimed that name. very demure, very mindful, very respectful of boundaries β¨
β¨ NAME β¨
renamenx β renames a key, but ONLY if the target key name doesn't already exist. it's giving "i'll move in but only if nobody's living there already" π π
π SYNOPSIS π
RENAMENX key newkey
that's it. two args. no drama. iconic.
π¦ DESCRIPTION π¦
So here's the vibe: RENAMENX renames key to newkey if newkey doesn't exist yet. that's the whole point, that's the "NX" in the name, no cap π
β οΈ and if key doesn't exist at all? it returns an error. like, girl, you can't rename a key that was never even here π
and okay, one kinda important thing if you're running in Cluster mode β both key and newkey have to live in the same hash slot. so in practice? only keys that share the same hash tag can be reliably renamed in cluster. plan accordingly bestie π§
π REPLY π
you get one of these two, both are valkey-protocol(7) Integer replies:
1β yasss,keywas renamed tonewkeyπ0β nope,newkeyalready exists, no rename happened π
β‘ COMPLEXITY β‘
O(1) β constant time. she is fast, she is efficient, she does not make you wait π«Ά
π ACL CATEGORIES π
@fast @keyspace @write
π HISTORY π
- Available since:
1.0.0β an OG, a legend, been here since the beginning π - Changed in
3.2.0: the command no longer returns an error when source and destination names are the same. so renaming a key to itself? chill now. no more tantrums π
π EXAMPLES π
watch her work:
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"
see what happened? myotherkey was already taken, so we got that big fat (integer) 0, and GET myotherkey still says "World". the original key stays untouched. boundaries = respected π«Ά slay
π₯ SEE ALSO π₯
the whole friend group, go say hi:
copy(3valkey)del(3valkey)dump(3valkey)exists(3valkey)expire(3valkey)expireat(3valkey)expiretime(3valkey)keys(3valkey)migrate(3valkey)move(3valkey)object(3valkey)object-encoding(3valkey)object-freq(3valkey)object-help(3valkey)object-idletime(3valkey)object-refcount(3valkey)persist(3valkey)pexpire(3valkey)pexpireat(3valkey)pexpiretime(3valkey)pttl(3valkey)randomkey(3valkey)rename(3valkey)restore(3valkey)scan(3valkey)sort(3valkey)sort_ro(3valkey)touch(3valkey)ttl(3valkey)type(3valkey)unlink(3valkey)wait(3valkey)waitaof(3valkey)
k bye, ily, go rename something responsibly π this page is from version 9.0.0, dated 2025-10-21, and it's the RENAMENX(3valkey) page β periodt. πβ¨
π¦ where this page comes from
- fedora 44: valkey-doc 9.0.3-2.fc44 Β· CC-BY-SA-4.0
- fedora 44: valkey-doc 9.0.6-1.fc44 Β· CC-BY-SA-4.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms