UNLINK(3valkey)

πŸ“¦
version 9.0.6 Β· 2 versions
, in fedora 44

okay so welcome to UNLINK(3valkey), straight out of the Valkey Command Manual πŸ’– this one's short, it's sweet, and it's lowkey a glow-up of DEL. let's get into it 🫢


🌸 NAME 🌸

unlink β€” deletes one or more keys, but asynchronously. like, it said it would do it, and it will, just… later πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

UNLINK key [key...]

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so this command is very similar to valkey-del(7) DEL β€” it removes the keys you name. and just like DEL, if a key doesn't exist, it gets ignored, no drama, no error, nothing πŸ’€

but here's the plot twist, bestie: UNLINK does the actual memory reclaiming in a different thread, so it is not blocking, whereas DEL is blocking. that's literally where the name comes from β€” the command just unlinks the keys from the keyspace, and the actual removal happens later, asynchronously. it's giving "I'll deal with it tomorrow" but make it a database πŸ‘‘


πŸ’– REPLY πŸ’–

valkey-protocol(7) Integer reply: the number of keys that were unlinked. so like, a lil count of how many keys got the boot ✨


πŸ”₯ COMPLEXITY πŸ”₯

  • O(1) for each key removed, regardless of its size. iconic, no cap.
  • then the command does O(N) work in a different thread to reclaim memory, where N is the number of allocations the deleted objects were composed of. so the expensive part is off doing its own thing in the background 🌈

πŸ‘‘ ACL CATEGORIES πŸ‘‘

@fast @keyspace @write


⭐ HISTORY ⭐

  • Available since: 4.0.0 (a classic, fr fr)

🌈 EXAMPLES 🌈

127.0.0.1:6379> SET key1 "Hello"
OK
127.0.0.1:6379> SET key2 "World"
OK
127.0.0.1:6379> UNLINK key1 key2 key3
(integer) 2

notice how key3 never existed and nobody made a big deal about it? yeah. ignored. it returned 2 because only two keys were actually there to unlink πŸ’… ate and left no crumbs.


πŸ’œ SEE ALSO πŸ’œ

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), renamenx(3valkey), restore(3valkey), scan(3valkey), sort(3valkey), sort_ro(3valkey), touch(3valkey), ttl(3valkey), type(3valkey), wait(3valkey), waitaof(3valkey)


and that's the whole page, bestie 🧚 this was Valkey 9.0.0, dated 2025-10-21. go unlink something, but like, responsibly πŸ’–βœ¨

πŸ“¦ where this page comes from