Skip to content

Ask the HotKV docs

Answers come only from these docs and can be wrong; check the linked pages before you rely on them.

FCALL

Last updated
FCALL function numkeys [key [key ...]] [arg [arg ...]]
Group
Scripting and functions
Complexity
Depends on the function
Arity
-3 (at least 3 words, counting the command name)
Flags
slow, write
HotKV Cloud
All plans
On-Premise
no license needed

FCALL runs a function registered by a library loaded with FUNCTION LOAD. 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 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.

The function’s return value, converted as described for EVAL.

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.
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

Same as Redis 7 and Valkey 8.

FCALL_RO, FUNCTION LOAD, FUNCTION LIST, EVAL