FUNCTION-LOAD(3valkey)
β¨ FUNCTION-LOAD β bestie, we're loading a library β¨
okay so real talk: this is function-load from the Valkey Command Manual (3valkey), and it's literally the command that creates a library. yes, the whole thing. no cap. π
πΈ NAME πΈ
function-load β Creates a library. π
π¦ SYNOPSIS π¦
FUNCTION LOAD [REPLACE] function-code
β¨ DESCRIPTION β¨
So you wanna load a library into Valkey? Obsessed. Here's the tea. β
The command takes a single mandatory parameter, and that parameter is the source code that implements the library. Just the whole code. Right there. In the command. We love a one-argument king. π
The library payload must start with a Shebang statement, and that shebang is what gives us the metadata about the library β like which engine to use and what the library's name is. The shebang format is:
#!<engine name> name=<library name>
and rn, currently the engine name must be lua. That's the only one. That's the whole roster. π
For the Lua engine, the implementation should declare one or more entry points to the library using the valkey-lua-api(7) server.register_function() API. Once it's loaded, you can call the functions in the library with the valkey-fcall(7) FCALL command β or valkey-fcall_ro(7) FCALL_RO when that's the applicable one. Pick your fighter. π₯
Now, the drama: if you try to load a library whose name already exists, the Valkey server is gonna hit you with an error. Periodt. But the REPLACE modifier changes that behavior β it lets you overwrite the existing library with the new contents. Slay. β¨
The command will return an error in the following circumstances, and yes we're listing all of them because you deserve to know:
- An invalid engine-name was provided. π
- The library's name already exists without the
REPLACEmodifier. π - A function in the library is created with a name that already exists in another library (even when
REPLACEis specified). π - The engine failed in creating the library's functions (due to a compilation error, for example). π₯
- No functions were declared by the library. (girl. the library is empty.)
For more information please refer to valkey-functions-intro(7) Introduction to Valkey Functions. iykyk π«Ά
π REPLY π
valkey-protocol(7) Bulk string reply: the library name that was loaded. that's it, that's the receipt. π§Ύ
π COMPLEXITY π
O(1) (considering compilation time is redundant)
π ACL CATEGORIES π
@scripting @slow @write
β 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. main character function fr fr π
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"
look at that. loaded, called, returned "hello". ate and left no crumbs. π₯
πΈ SEE ALSO πΈ
eval(3valkey), evalsha(3valkey), evalsha_ro(3valkey), eval_ro(3valkey), fcall(3valkey), fcall_ro(3valkey), function(3valkey), function-delete(3valkey), function-dump(3valkey), function-flush(3valkey), function-help(3valkey), function-kill(3valkey), function-list(3valkey), function-restore(3valkey), function-stats(3valkey), script(3valkey), script-debug(3valkey), script-exists(3valkey), script-flush(3valkey), script-help(3valkey), script-kill(3valkey), script-load(3valkey), script-show(3valkey)
and that's the whole page bestie!! this one's from Valkey9.0.0, dated2025-10-21, and it's giving manual page, it's giving library-creating icon, it's giving everything. go load something. ily. π¦ππΈ
π¦ where this page comes from
- fedora 44: valkey-doc 9.0.3-2.fc44 Β· CC-BY-SA-4.0
- fedora 44: valkey-doc 9.0.6-1.fc44 Β· CC-BY-SA-4.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms