COPY
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.
Options
Section titled “Options”| 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.
Return value
Section titled “Return value”| 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 samewhen both names and databases match.ERR DB index is out of rangefor a database that does not exist.ERR value is not an integer or out of rangewhen the database index is not an integer.ERR syntax errorfor any other argument.
Examples
Section titled “Examples”127.0.0.1:6379> SET config:v1 "max=10"OK127.0.0.1:6379> COPY config:v1 config:v2(integer) 1127.0.0.1:6379> COPY config:v1 config:v2(integer) 0127.0.0.1:6379> COPY config:v1 config:v2 REPLACE(integer) 1127.0.0.1:6379> COPY config:v1 config:v1 DB 1(integer) 1Compatibility
Section titled “Compatibility”Same as Redis 7 and Valkey 8.
See also
Section titled “See also”In a cluster: Keys, slots and commands in a cluster
Was this page helpful?
Thanks for the feedback.