# FUNCTION

> Manage Lua function libraries.

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

```
FUNCTION LOAD [REPLACE] function-code
FUNCTION DELETE library-name
FUNCTION LIST [LIBRARYNAME library-name-pattern] [WITHCODE]
FUNCTION STATS
FUNCTION DUMP
FUNCTION RESTORE serialized-value [FLUSH | APPEND | REPLACE]
FUNCTION FLUSH [ASYNC | SYNC]
FUNCTION KILL
FUNCTION HELP
```

- Group: Scripting and functions
- HotKV Cloud: all plans
- On-Premise: no license needed

`FUNCTION` is a container for subcommands that manage function libraries,
whose functions you call with [FCALL](https://docs.hotkv.com/commands/fcall/index.md) and
[FCALL_RO](https://docs.hotkv.com/commands/fcall_ro/index.md). Libraries are part of the dataset: they are
persisted and replicated like keys. `LOAD`, `DELETE`, `RESTORE` and `FLUSH`
change them and are refused on a read-only replica.

| Subcommand | What it does |
| --- | --- |
| [FUNCTION LOAD](https://docs.hotkv.com/commands/function-load/index.md) | Load a library, or replace one |
| [FUNCTION DELETE](https://docs.hotkv.com/commands/function-delete/index.md) | Delete a library and its functions |
| [FUNCTION LIST](https://docs.hotkv.com/commands/function-list/index.md) | List libraries and their functions |
| [FUNCTION STATS](https://docs.hotkv.com/commands/function-stats/index.md) | Count libraries and functions |
| [FUNCTION DUMP](https://docs.hotkv.com/commands/function-dump/index.md) | Serialize all libraries |
| [FUNCTION RESTORE](https://docs.hotkv.com/commands/function-restore/index.md) | Load libraries from a `FUNCTION DUMP` payload |
| [FUNCTION FLUSH](https://docs.hotkv.com/commands/function-flush/index.md) | Delete all libraries |
| [FUNCTION KILL](https://docs.hotkv.com/commands/function-kill/index.md) | Stop a running function that has not written yet |
| `FUNCTION HELP` | A short description of each subcommand |

An unknown subcommand replies with
`ERR unknown subcommand '<name>'. Try FUNCTION HELP.`

## Examples

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

## Compatibility

The same subcommands as Redis 7 and Valkey 8. The payload of
[FUNCTION DUMP](https://docs.hotkv.com/commands/function-dump/index.md) is HotKV's own and cannot be
exchanged with Redis or Valkey.

## See also

[FCALL](https://docs.hotkv.com/commands/fcall/index.md), [SCRIPT](https://docs.hotkv.com/commands/script/index.md),
[EVAL](https://docs.hotkv.com/commands/eval/index.md)