Debian Codegraph @

contrib/sample_collect_script.lua

raw symbols SCIP
1 -- Example collect script for -script option
2 -- This returns a Lua table with alternating keys and values.
3 -- Both keys and values must be strings, similar to a HGETALL result.
4 -- More info about Redis Lua scripting: https://valkey.io/commands/eval
5
6 local result = {}
7
8 -- Add all keys and values from some hash in db 5
9 redis.call("SELECT", 5)
10 local r = redis.call("HGETALL", "some-hash-with-stats")
11 if r ~= nil then
12 for _,v in ipairs(r) do
13 table.insert(result, v) -- alternating keys and values
14 end
15 end
16
17 -- Set foo to 42
18 table.insert(result, "foo")
19 table.insert(result, "42") -- note the string, use tostring() if needed
20
21 return result