Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

redis lua debugger -- why can't I print ARGV

Tags:

redis

lua

I am trying a very simple lua script in the debug mode, and to inspect the ARGV.

local jobExists = redis.call('exists', ARGV[1])
if jobExists then 
  return false
end

And, I run the the debugger as below:

redis-cli --ldb --eval ./is_running.lua 0 , user:root

I am able to access the value of ARGV[1] within the program and it works fine. But when I try to print, it says 'no such variable'.

lua debugger> print ARGV[1]
No such variable.
lua debugger> 

So, it doesn't seem to be a lua table or array. When I print ARGV instead of ARGV[1], i get the following output

lua debugger> print ARGV
<value> {"user:root"}

So, is this a limitation of the debugger, or am I doing it wrong?

like image 295
Mopparthy Ravindranath Avatar asked Jul 03 '26 15:07

Mopparthy Ravindranath


1 Answers

You're NOT doing anything wrong.

With lua debuger, you can only print the value of the whole table (ARGV is, in fact, a lua table), and you CANNOT only print an item of the table.

When you type the following command in the debuger:

print varname

Redis searches lua variables to find if there's a variable named varname. If it finds one, Redis prints the value of the variable. However, if there's no one named varname, it prints No such variable.

In your case, print ARGV[1] makes Redis try to find a variable, whose name is exactly ARGV[1], and there's no such a variable, i.e. strcmp("ARGV[1]", "ARGV") != 0. So you get No such variable.

On the other hand, with print ARGV, Redis can find a (global) variable, whose name is exactly ARGV. So it prints the value the variable: all elements in the table.

like image 91
for_stack Avatar answered Jul 05 '26 16:07

for_stack



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!