Category Archives: LUA

Redis: print to STDOUT from a LUA script

When you want to print to STDOUT from a LUA script executed by “redis-cli –raw –eval”, it doesn’t print to STDOUT but in Syslog. You will need to use “return” instead.

Let’s help yourself with a “logit” function, like this:

local log = {}
local function logit(msg)
  log[#log+1] = msg
end

-- Some code

    -- Log my string
    logit(mystring)

-- Some more code

-- print log to STDOUT
return log

That’s awesome till you don’t know how to pass arguments to your Redis LUA script ! :-)

Redis: passing args to a LUA script

How did it came in their brain that the arguments where not stored in the ARG[] array but in the KEYS[] one ?

So if you want to call your Redis LUA script this way:

redis-cli --raw --eval myscript.lua arg1 arg2 ...

You have to access your args this way in the LUA script:

local arg1=KEYS[1]
local arg2=KEYS[2]
...

That’s awesome till you don’t know how to STDOUT print some results :-)