Command builders for Redis Functions (Redis 7+).
Redis Functions provide a persistent, named alternative to Lua scripting.
Libraries are loaded once and survive server restarts, and individual
functions within a library are invoked by name with FCALL / FCALL_RO.
All functions are pure and return a command list for use with
Redis.command/2 or Redis.pipeline/2.
Examples
# Load a function library
Redis.command(conn, Function.load("#!lua name=mylib\nredis.register_function('myfunc', function(keys, args) return keys[1] end)"))
# Call a function
Redis.command(conn, Function.fcall("myfunc", ["key1"], ["arg1"]))
# List all libraries
Redis.command(conn, Function.list())
Summary
Functions
FUNCTION DELETE -- remove a function library by name.
FUNCTION DUMP -- return a serialized payload of all loaded libraries.
FCALL -- invoke a Redis Function by name.
FCALL_RO -- invoke a read-only Redis Function by name.
FUNCTION FLUSH -- delete all function libraries.
FUNCTION LIST -- list loaded function libraries.
FUNCTION LOAD -- load a function library into Redis.
FUNCTION RESTORE -- restore libraries from a serialized payload.
FUNCTION STATS -- return information about function execution.
Functions
FUNCTION DELETE -- remove a function library by name.
@spec dump() :: [String.t()]
FUNCTION DUMP -- return a serialized payload of all loaded libraries.
The result can be restored on another server with restore/2.
FCALL -- invoke a Redis Function by name.
The keys list is passed as KEYS and args as ARGV inside the function.
The number of keys is computed automatically.
Function.fcall("myfunc", ["key1"], ["arg1"])
#=> ["FCALL", "myfunc", "1", "key1", "arg1"]
FCALL_RO -- invoke a read-only Redis Function by name.
Identical to fcall/3 but uses the read-only variant, which is safe
for use on replicas.
FUNCTION FLUSH -- delete all function libraries.
Options
:mode-:asyncor:sync(default: server decides)
FUNCTION LIST -- list loaded function libraries.
Options
:libraryname- filter by library name pattern:withcode- include library source code in the response
FUNCTION LOAD -- load a function library into Redis.
Pass replace: true to overwrite an existing library with the same name.
Function.load("#!lua name=mylib\nredis.register_function(...)")
Function.load(code, replace: true)
FUNCTION RESTORE -- restore libraries from a serialized payload.
Options
:flush- delete all existing libraries before restoring:append- append to existing libraries (error on name conflict):replace- replace existing libraries with same name
@spec stats() :: [String.t()]
FUNCTION STATS -- return information about function execution.