# RESTORE

> Create a key from a payload produced by DUMP.

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

```
RESTORE key ttl serialized-value [REPLACE] [ABSTTL] [IDLETIME seconds] [FREQ frequency]
```

- Group: Keys
- Complexity: O(N) where N is the size of the value
- HotKV Cloud: all plans
- On-Premise: no license needed

`RESTORE` creates `key` from a payload made by [DUMP](https://docs.hotkv.com/commands/dump/index.md). It
accepts payloads from HotKV and from Redis. `ttl` is the time to live in
milliseconds, or `0` for none. If the time to live has already passed, the
command succeeds but no key is left (with `REPLACE`, an existing key of that
name is deleted).

## Options

| Option | Effect |
| --- | --- |
| `REPLACE` | Overwrite `key` if it exists. Without it, an existing key is an error. |
| `ABSTTL` | Read `ttl` as an absolute Unix time in milliseconds instead of a duration. |
| `IDLETIME seconds` | Set the key's idle time, used when the eviction policy is LRU-based. Must be 0 or more. |
| `FREQ frequency` | Set the key's access frequency, used when the eviction policy is LFU-based. Must be 0 to 255. |

`IDLETIME` and `FREQ` cannot be combined. The options are checked first, then
whether the key exists, then the time to live.

## Return value

| Case | RESP2 | RESP3 |
| --- | --- | --- |
| Restored | Simple string `OK` | Simple string `OK` |

Errors:

- `BUSYKEY Target key name already exists.` when `key` exists and `REPLACE`
  was not given.
- `ERR DUMP payload version or checksum are wrong` for a damaged payload or
  one from a newer format than HotKV reads.
- `ERR Bad data format` for a payload that passes the checksum but cannot be
  decoded.
- `ERR Invalid TTL value, must be >= 0`,
  `ERR Invalid IDLETIME value, must be >= 0` and
  `ERR Invalid FREQ value, must be >= 0 and <= 255`.
- `ERR syntax error` for an unknown option, or `IDLETIME` together with
  `FREQ`.

## Examples

```
127.0.0.1:6379> RESTORE greeting 0 "\x00\x05hello\t\x00\xb3\x80\x8e\xba1\xb2C\xbb"
OK
127.0.0.1:6379> GET greeting
"hello"
127.0.0.1:6379> RESTORE greeting 0 "\x00\x05hello\t\x00\xb3\x80\x8e\xba1\xb2C\xbb"
(error) BUSYKEY Target key name already exists.
127.0.0.1:6379> RESTORE greeting 60000 "\x00\x05hello\t\x00\xb3\x80\x8e\xba1\xb2C\xbb" REPLACE
OK
127.0.0.1:6379> TTL greeting
(integer) 60
```

## Compatibility

Same options and replies as Redis 7 and Valkey 8.

## See also

[DUMP](https://docs.hotkv.com/commands/dump/index.md), [RESTORE-ASKING](https://docs.hotkv.com/commands/restore-asking/index.md),
[MIGRATE](https://docs.hotkv.com/commands/migrate/index.md), [COPY](https://docs.hotkv.com/commands/copy/index.md)