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.

COPY

Last updated
COPY source destination [DB destination-db] [REPLACE]
Group
Keys
Complexity
O(N) where N is the size of the value copied
Arity
-3 (at least 3 words, counting the command name)
Flags
write
Keys
first 1, last 2, step 1
HotKV Cloud
All plans
On-Premise
no license needed

COPY duplicates the value at source into destination, including its time to live. The source is left as it is. By default nothing is copied when destination already exists.

Option Effect
DB destination-db Write the copy into this database instead of the selected one. On a cluster node the default cluster-databases 1 refuses another database (ERR Copying to another database is not allowed in cluster mode); with a higher cluster-databases it works between the node’s databases.
REPLACE Overwrite destination if it exists.

The options can come in any order.

Case RESP2 RESP3
Copied Integer 1 Integer 1
source does not exist, or destination exists and REPLACE was not given Integer 0 Integer 0

Errors:

  • ERR source and destination objects are the same when both names and databases match.
  • ERR DB index is out of range for a database that does not exist.
  • ERR value is not an integer or out of range when the database index is not an integer.
  • ERR syntax error for any other argument.
127.0.0.1:6379> SET config:v1 "max=10"
OK
127.0.0.1:6379> COPY config:v1 config:v2
(integer) 1
127.0.0.1:6379> COPY config:v1 config:v2
(integer) 0
127.0.0.1:6379> COPY config:v1 config:v2 REPLACE
(integer) 1
127.0.0.1:6379> COPY config:v1 config:v1 DB 1
(integer) 1

Same as Redis 7 and Valkey 8.

RENAME, MOVE, DUMP, RESTORE

In a cluster: Keys, slots and commands in a cluster