Skip to content

Instantly share code, notes, and snippets.

@itamarhaber
Last active April 19, 2017 20:28
Show Gist options
  • Save itamarhaber/e7dcae6ff5fa18a030ef to your computer and use it in GitHub Desktop.
Save itamarhaber/e7dcae6ff5fa18a030ef to your computer and use it in GitHub Desktop.
Snippets accompanying Redis Lua Debugger blog post
rld.start()
local function isanswer(n)
local answer = 42
if n == answer then
return true
else
return false
end
end
local t = isanswer(ARGV[1])
return ARGV[1] .. " " .. (t and "is" or "isn't") .. " the answer"
foo@bar:~$ redis-cli --eval rld.lua
"rld v0.1.0 loaded to Redis"
foo@bar:~$ redis-cli --eval prog.lua , 42
"42 isn't the answer"
foo@bar:~$ tail -n 19 /var/log/redis_6379.log
[891] 31 Dec 06:37:09.001 # [rld] -- rld v0.1.0 loaded to Redis
[891] 31 Dec 06:37:09.492 # [rld] -- rld v0.1.0 started
[891] 31 Dec 06:37:09.492 # [rld] ARGV[1] = '42'
[891] 31 Dec 06:37:09.492 # [rld] at Lua:@user_script (line: 10)
[891] 31 Dec 06:37:09.493 # [rld] at Lua:@user_script (line: 12)
[891] 31 Dec 06:37:09.493 # [rld] new [isanswer] = (function)
[891] 31 Dec 06:37:09.493 # [rld] call to function Lua:isanswer
[891] 31 Dec 06:37:09.493 # [rld] args [n] = '42'
[891] 31 Dec 06:37:09.493 # [rld] at Lua:isanswer (line: 4)
[891] 31 Dec 06:37:09.493 # [rld] at Lua:isanswer (line: 5)
[891] 31 Dec 06:37:09.493 # [rld] new [answer] = 42
[891] 31 Dec 06:37:09.493 # [rld] at Lua:isanswer (line: 8)
[891] 31 Dec 06:37:09.493 # [rld] return from function Lua:isanswer
[891] 31 Dec 06:37:09.493 # [rld] at Lua:@user_script (line: 14)
[891] 31 Dec 06:37:09.493 # [rld] new [t] is false
[891] 31 Dec 06:37:09.493 # [rld] return from function Lua:@user_script
[891] 31 Dec 06:37:09.494 # [rld] -- profiler summary:
[891] 31 Dec 06:37:09.494 # [rld] -- Lua:isanswer called x1 times
[891] 31 Dec 06:37:09.494 # [rld] -- rld exited: end of script.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment