Available since: 7.0.0
Time complexity: O(1) (considering compilation time is redundant)
Load a library to Redis.
The command's gets a single mandatory parameter which is the source code that implements the library.
The library payload must start with Shebang statement that provides a metadata about the library (like the engine to use and the library name).
#!<engine name> name=<library name>. Currently engine name must be
For the Lua engine, the implementation should declare one or more entry points to the library with the
Once loaded, you can call the functions in the library with the
FCALL_RO when applicable) command.
When attempting to load a library with a name that already exists, the Redis server returns an error.
REPLACE modifier changes this behavior and overwrites the existing library with the new contents.
The command will return an error in the following circumstances:
For more information please refer to Introduction to Redis Functions.
@string - the library name that was loaded
The following example will create a library named
mylib with a single function,
myfunc, that returns the first argument it gets.
redis> FUNCTION LOAD "#!lua name=mylib \n redis.register_function('myfunc', function(keys, args) return args end)" mylib redis> FCALL myfunc 0 hello "hello"