FUNCTION-LOAD(3valkey)

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

✨ 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 REPLACE modifier. πŸ™ˆ
  • A function in the library is created with a name that already exists in another library (even when REPLACE is 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 Valkey 9.0.0, dated 2025-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