# RENAME

> Rename a key, overwriting the destination if it exists.

URL: https://docs.hotkv.com/commands/rename/

```
RENAME key newkey
```

- Group: Keys
- Complexity: O(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

| Case | RESP2 | RESP3 |
| --- | --- | --- |
| Renamed | Simple string `OK` | Simple string `OK` |
| `key` does not exist | Error `ERR no such key` | Error |

## Examples

```
127.0.0.1:6379> SET draft "v1"
OK
127.0.0.1:6379> RENAME draft published
OK
127.0.0.1:6379> GET published
"v1"
127.0.0.1:6379> RENAME draft other
(error) ERR no such key
```

## Compatibility

Same as Redis 7 and Valkey 8.

## See also

[RENAMENX](https://docs.hotkv.com/commands/renamenx/index.md), [COPY](https://docs.hotkv.com/commands/copy/index.md),
[MOVE](https://docs.hotkv.com/commands/move/index.md)