# FUNCTION RESTORE

> Load function libraries from a FUNCTION DUMP payload.

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

```
FUNCTION RESTORE serialized-value [FLUSH | APPEND | REPLACE]
```

- Group: Scripting and functions
- Complexity: O(N) where N is the number of libraries
- HotKV Cloud: all plans
- On-Premise: no license needed

`FUNCTION RESTORE` loads the libraries in a payload made by
[FUNCTION DUMP](https://docs.hotkv.com/commands/function-dump/index.md). It is all or nothing: if any library
fails to load, the libraries that were loaded before the command are put back
and nothing changes.

## Options

| Policy | Effect |
| --- | --- |
| `APPEND` | Add the payload's libraries. Fails if any of them is already loaded. This is the default. |
| `REPLACE` | Add the payload's libraries, replacing loaded libraries of the same name. |
| `FLUSH` | Delete all loaded libraries first, then load the payload's. |

## Return value

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

Errors:

- `ERR Library <name> already exists` with `APPEND` when a library in the
  payload is already loaded.
- `ERR Wrong restore policy given, value should be either FLUSH, APPEND or REPLACE.`
- Any [FUNCTION LOAD](https://docs.hotkv.com/commands/function-load/index.md) error for a library in the
  payload.

## Examples

```
127.0.0.1:6379> FUNCTION DUMP
"#!lua name=util\nredis.register_function('echo', function(keys, args) return args[1] end)\x00"
127.0.0.1:6379> FUNCTION FLUSH
OK
127.0.0.1:6379> FUNCTION RESTORE "#!lua name=util\nredis.register_function('echo', function(keys, args) return args[1] end)\x00"
OK
127.0.0.1:6379> FCALL echo 0 "back"
"back"
```

## Compatibility

Same policies and replies as Redis 7 and Valkey 8, but only HotKV payloads are
accepted (see [FUNCTION DUMP](https://docs.hotkv.com/commands/function-dump/index.md)).

## See also

[FUNCTION DUMP](https://docs.hotkv.com/commands/function-dump/index.md), [FUNCTION LOAD](https://docs.hotkv.com/commands/function-load/index.md),
[FUNCTION FLUSH](https://docs.hotkv.com/commands/function-flush/index.md)