COPY(3valkey)

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

πŸ’– COPY(3valkey) πŸ’–

okay bestie, welcome to the Valkey Command Manual entry for copy β€” yes, it literally copies the value of a key to a new key, and yes it's as iconic as it sounds 🫢


✨ NAME ✨

copy β€” copies the value of a key to a new key. no cap, that's the whole job description πŸ’…


🌸 SYNOPSIS 🌸

COPY source destination [DB destination-db] [REPLACE]

πŸ¦‹ DESCRIPTION πŸ¦‹

so the tea is: this command copies the value stored at the source key over to the destination key. simple. elegant. main character energy ✨

by default, the destination key gets created in the logical database that your connection is already using. but if you wanna be extra, the DB option lets you specify an alternative logical database index for the destination key. slay 🌈

the command returns zero when the destination key already exists β€” like, it's not gonna overwrite anything unless you tell it to. that's where REPLACE comes in: it removes the destination key before copying the value to it. so yeah, REPLACE is the "no thoughts, just overwrite" option πŸ’€


πŸ‘‘ REPLY πŸ‘‘

one of the following, bestie:

  • valkey-protocol(7) Integer reply: 1 if source was copied. ate. πŸ”₯
  • valkey-protocol(7) Integer reply: 0 if source was not copied when the destination key already exists. it's giving "nah, that key's taken" 😭

πŸ’… COMPLEXITY πŸ’…

  • O(N) worst case for collections, where N is the number of nested items.
  • O(1) for string values.

so like, strings are basically instant, but collections? they got layers, and layers cost πŸ“


πŸŽ€ ACL CATEGORIES πŸŽ€

@keyspace @slow @write


⭐ HISTORY ⭐

  • Available since: 6.2.0

she's not ancient, she's a modern queen πŸ‘‘


🧚 EXAMPLES 🧚

SET dolly "sheep"
COPY dolly clone
GET clone

look at her go πŸ‘πŸ’–


πŸ’œ SEE ALSO πŸ’œ

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), unlink(3valkey), wait(3valkey), waitaof(3valkey)

go read those next, iykyk πŸ“šβœ¨


this page is from Valkey 9.0.0, dated 2025-10-21, and it's the COPY(3valkey) page from the Valkey Command Manual β€” mwah, no notes, periodt πŸ’…πŸ’–πŸ¦‹

πŸ“¦ where this page comes from