RENAMENX
RENAMENX key newkey
- Group
- Keys
- Complexity
- O(1)
- Arity
- 3 (exactly, counting the command name)
- Flags
- write, fast
- Keys
- first 1, last 2, step 1
- HotKV Cloud
- All plans
- On-Premise
- no license needed
RENAMENX renames key to newkey only when newkey does not exist. The
value keeps its time to live. Renaming a key to its own name is treated as
“the name is taken” and replies 0.
In a cluster, key and newkey must hash to the same slot.
Return value
Section titled “Return value”| Case | RESP2 | RESP3 |
|---|---|---|
| Renamed | Integer 1 |
Integer 1 |
newkey already exists |
Integer 0 |
Integer 0 |
key does not exist |
Error ERR no such key |
Error |
Examples
Section titled “Examples”127.0.0.1:6379> MSET a "first" b "second"OK127.0.0.1:6379> RENAMENX a b(integer) 0127.0.0.1:6379> RENAMENX a c(integer) 1127.0.0.1:6379> GET c"first"Compatibility
Section titled “Compatibility”Same as Redis 7 and Valkey 8.
See also
Section titled “See also”Was this page helpful?
Thanks for the feedback.