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?
Scripts are executed in Redis by an embedded execution engine. Presently, Redis supports a single scripting engine, the Lua 5.1 interpreter.
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 .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With