1

I have the "Hello World" program in Lua script. I am trying to call the script from (Chocolatey) Redis client. I keep getting this error (error) ERR Error compiling script (new function): user_script:1: function argument expected near '.'

Redis Script: "hello.lua"

local msg = "Hello, world!"
return msg

Chocolatey Redis Client:

127.0.0.1:6379> EVAL "D:\hello.lua" 0

Error Message

(error) ERR Error compiling script (new function): user_script:1: function argument expected near '.'

1 Answer 1

6

EVAL accepts the script itself, not a filename.

Try this:

EVAL 'local msg = "Hello, world!" return msg' 0

EDIT: to execute a script in a file, redis-cli provides the --eval switch that you can use as follows:

redis-cli --eval <path-to-script-file> [key1 [key2] ...] , [arg1 [arg2] ...]

I'm not familiar with the Windows fork, but it should be supported by it as well in all likelihood.

In *nix, you can also use the shell to provide the contents of the script to the cli, for example:

redis-cli SCRIPT LOAD "$(cat path-to-script-file)"

will load the contents in the file to Redis. There should be a similar way for achieving this in Windows but that's outside my current scope ;)

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for your quick reply Itamar. I finally could see the output. I was struggling with it for a long time. Thank you again. Also can you please help me with how to call a lua scipt file from redis client. How can I pass the parameters to the file and accept the values returned from the script file.
I assume you're using the Windows cli as your client - correct?
I use the "start redis-server" and "start redis-cli" commands in the Windows cmd to start the Redis Server and Client respectively. They are also command prompts and I try to fetch the data from this client.
@invincible if you find my answer adequate, please mark it so

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.