FCALL(3valkey)

πŸ“¦
version 9.0.6 Β· 2 versions
, in fedora 44

πŸ’– FCALL β€” aka fcall from the Valkey Command Manual ✨

okay bestie, sit down, hydrate, because today we're talking about fcall β€” the little command that goes "hey server, run this function for me" and the server is like "bet." 🫢 It lives in the Valkey Command Manual, section 3, and it's genuinely iconic.


🌸 NAME 🌸

fcall β€” Invokes a function. πŸ’…


✨ SYNOPSIS ✨

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

πŸŽ€ DESCRIPTION πŸŽ€

Invoke a function. That's the whole vibe. πŸ¦‹

Functions get loaded onto the server with the valkey-function-load(7) FUNCTION LOAD command. The first argument is the name of a loaded function. So like, you can't just call a function that isn't there β€” no cap, the server has to already know her. πŸ‘‘

The second argument is the number of input key name arguments, and then right after that come all the keys the function accesses. In Lua, those input key names show up to the function as a table β€” and that table is the callback's first argument. 🧚

Important: To ensure the correct execution of functions, both in standalone and clustered deployments, all names of keys that a function accesses must be explicitly provided as input key arguments. The function should only access keys whose names are given as input arguments. Functions should never access keys with programmatically-generated names or based on the contents of data structures stored in the database. 🚨 This is not a drill, bestie. Do not do it. It's giving chaos and we don't want that.

Any additional input argument should not represent names of keys. Those are just regular arguments, and they get passed in a Lua table as the callback's second argument. πŸ“

For more info, please go read the valkey-programmability(7) and valkey-functions-intro(7) Introduction to Valkey Functions pages. They ate, fr fr. πŸ“š


πŸ’Œ REPLY πŸ’Œ

The return value depends on the function that was executed. So like… it's giving mystery, it's giving "depends on her mood." πŸ€·β™€οΈ


πŸ”₯ COMPLEXITY πŸ”₯

Depends on the function that is executed. Same energy as above honestly. 😭


πŸ‘‘ ACL CATEGORIES πŸ‘‘

  • @scripting
  • @slow

🌈 HISTORY 🌈

  • Available since: 7.0.0 ⭐

πŸ’… EXAMPLES πŸ’…

The following example will create a library named mylib with a single function, myfunc, that returns the first argument it gets. Cute, simple, effective. πŸŽ€

127.0.0.1:6379> FUNCTION LOAD "#!lua name=mylib \n server.register_function('myfunc', function(keys, args) return args[1] end)"
"mylib"
127.0.0.1:6379> FCALL myfunc 0 hello
"hello"

Not her returning "hello" right back at you like the polite queen she is. πŸ’–


πŸ¦‹ SEE ALSO πŸ¦‹


and that's the whole page bestie 🫢 this was Valkey 9.0.0, dated 2025-10-21, filed under FCALL(3valkey) β€” go forth and call your functions responsibly, mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from