# FCALL

> Call a function from a loaded function library.

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

```
FCALL function numkeys [key [key ...]] [arg [arg ...]]
```

- Group: Scripting and functions
- Complexity: Depends on the function
- HotKV Cloud: all plans
- On-Premise: no license needed

`FCALL` runs a function registered by a library loaded with
[FUNCTION LOAD](https://docs.hotkv.com/commands/function-load/index.md). Like a script, the function runs
atomically. It receives the `numkeys` key names after `numkeys` as its first
argument and the remaining arguments as its second. Function names are not
case-sensitive.

Unlike scripts, function libraries are part of the dataset: they are saved
with snapshots and the AOF, and are copied to replicas, so they survive a
restart and do not need to be reloaded by clients. See
[Functions](https://docs.hotkv.com/develop/functions/index.md) for the full guide.

The function's flags (set with `redis.register_function`) decide where it may
run, as for scripts: a function without `no-writes` is refused on a read-only
replica, and one without `allow-oom` when the server is over `maxmemory`.

## Return value

The function's return value, converted as described for
[EVAL](https://docs.hotkv.com/commands/eval/index.md).

Errors:

- `ERR Function not found` when no loaded library registers that name.
- `ERR Number of keys can't be greater than number of args` and
  `ERR Number of keys can't be negative` for a bad `numkeys`.
- The `BUSY`, read-only and out-of-memory errors described for
  [EVAL](https://docs.hotkv.com/commands/eval/index.md).

## Examples

```
127.0.0.1:6379> FUNCTION LOAD "#!lua name=counters\nredis.register_function('bump', function(keys, args) return redis.call('INCRBY', keys[1], args[1]) end)"
"counters"
127.0.0.1:6379> FCALL bump 1 hits 10
(integer) 10
127.0.0.1:6379> FCALL BUMP 1 hits 5
(integer) 15
127.0.0.1:6379> FCALL nosuch 0
(error) ERR Function not found
```

## Compatibility

Same as Redis 7 and Valkey 8.

## See also

[FCALL_RO](https://docs.hotkv.com/commands/fcall_ro/index.md), [FUNCTION LOAD](https://docs.hotkv.com/commands/function-load/index.md),
[FUNCTION LIST](https://docs.hotkv.com/commands/function-list/index.md), [EVAL](https://docs.hotkv.com/commands/eval/index.md)