COPY(3valkey)
π 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
- 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