RENAME
RENAME key newkey
- Group
- Keys
- Complexity
- O(1)
- Arity
- 3 (exactly, counting the command name)
- Flags
- write
- Keys
- first 1, last 2, step 1
- HotKV Cloud
- All plans
- On-Premise
- no license needed
RENAME moves the value at key to newkey. If newkey already exists, its
value is replaced. The value keeps its time to live. Renaming a key to its own
name succeeds and changes nothing.
In a cluster, key and newkey must hash to the same slot.
Return value
Section titled “Return value”| Case | RESP2 | RESP3 |
|---|---|---|
| Renamed | Simple string OK |
Simple string OK |
key does not exist |
Error ERR no such key |
Error |
Examples
Section titled “Examples”127.0.0.1:6379> SET draft "v1"OK127.0.0.1:6379> RENAME draft publishedOK127.0.0.1:6379> GET published"v1"127.0.0.1:6379> RENAME draft other(error) ERR no such keyCompatibility
Section titled “Compatibility”Same as Redis 7 and Valkey 8.
See also
Section titled “See also”Was this page helpful?
Thanks for the feedback.