Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing an argument to Redis Lua script

I am trying to pass an argument to my Redis Lua script using the following syntax:

redis-cli -h 127.0.0.1 -p 6379 -a my-super-secret-auth-key --eval /tmp/test.lua 0 60

However in my script when I do: print (ARGV[1]);

I get (nil) returned. What am I doing wrong? How can I properly pass an argument to my script?

like image 747
Brad Avatar asked Jul 29 '17 00:07

Brad


People also ask

Is Redis written in Lua?

Scripts are executed in Redis by an embedded execution engine. Presently, Redis supports a single scripting engine, the Lua 5.1 interpreter.

Is Redis Lua script Atomic?

Redis has the ability to execute Lua scripts on the server side. Lua scripts are executed atomically, that is, no other script or command will run while a script is running, which gives us the same transactional semantics as MULTI / EXEC .


1 Answers

You need to use comma (,) to separate KEYS and ARGV parameters even when you don't pass any KEYS (assuming you want 0 and 60 to be passed as ARGV):

redis-cli -h 127.0.0.1 -p 6379 -a my-super-secret-auth-key --eval /tmp/test.lua , 0 60

In your case these parameters are taken as KEYS, not as ARGV parameters. See Running Lua scripts in the Redis docs.

like image 128
Paul Kulchenko Avatar answered Nov 04 '22 22:11

Paul Kulchenko