Page
src/content/docs/how-to/load-and-execute-functions.mdx (Load and Execute Functions)
Problem
The set_then_get Lua example registers the function with named parameters:
#!lua name=example_module
server.register_function('set_then_get', function(key, value)
server.call('SET', key, value)
return server.call('GET', key)
end)
Valkey Functions always invoke a registered function with exactly two
arguments — keys (array) and args (array). So key binds to the whole
keys array and value to the whole args array (both Lua tables), not
strings. When called as fcall("set_then_get", keys: ["page:home:visits"], args: ["1"]), the function runs server.call('SET', <table>, <table>) and
the server rejects it:
ResponseError: Command arguments must be strings or integers
The client-side fcall/function_load calls are correct — the bug is only
in the Lua function body.
Scope
This same broken signature appears in all language tabs on the page
(Python, Java, Node, Go, PHP, C#, Ruby). The other example on the page,
update_visits, uses the correct array-indexing style and works.
Suggested fix
Use the (keys, args) signature and index into the arrays, across every
language tab:
#!lua name=example_module
server.register_function('set_then_get', function(keys, args)
server.call('SET', keys[1], args[1])
return server.call('GET', keys[1])
end)
How it was found
Caught while verifying Ruby doc examples against the published
valkey-glide-rb 1.0.0.pre.rc2 gem with a live Valkey server (PRs #299/#300).
Page
src/content/docs/how-to/load-and-execute-functions.mdx(Load and Execute Functions)Problem
The
set_then_getLua example registers the function with named parameters:Valkey Functions always invoke a registered function with exactly two
arguments —
keys(array) andargs(array). Sokeybinds to the wholekeys array and
valueto the whole args array (both Lua tables), notstrings. When called as
fcall("set_then_get", keys: ["page:home:visits"], args: ["1"]), the function runsserver.call('SET', <table>, <table>)andthe server rejects it:
The client-side
fcall/function_loadcalls are correct — the bug is onlyin the Lua function body.
Scope
This same broken signature appears in all language tabs on the page
(Python, Java, Node, Go, PHP, C#, Ruby). The other example on the page,
update_visits, uses the correct array-indexing style and works.Suggested fix
Use the
(keys, args)signature and index into the arrays, across everylanguage tab:
How it was found
Caught while verifying Ruby doc examples against the published
valkey-glide-rb1.0.0.pre.rc2 gem with a live Valkey server (PRs #299/#300).