microsoftarchive / redis

Redis is an in-memory database that persists on disk. The data model is key-value, but many different kind of values are supported: Strings, Lists, Sets, Sorted Sets, Hashes
http://redis.io
Other
20.84k stars 5.38k forks source link

redis-cli --eval and ARGV #441

Closed jgranduel closed 8 years ago

jgranduel commented 8 years ago

Hi,

I'm learning Redis Lua scripting with redis-3.0.501 on Win 7/Win 8.1. I want to get values from ARGV.

With Redis REPL, I get :

127.0.0.1:6379> EVAL "return {KEYS[1], ARGV[1]}" 1 a b
1) "a"
2) "b"

If I put "return {KEYS[1], ARGV[1]}" into a file, say test.lua

PS> Set-Content -Path test.lua -Value "return {KEYS[1], ARGV[1]}"
PS>  redis-cli -a sb --eval test.lua a , b
1) "a"

ARGV is nil.

But I can do the form:

PS> redis-cli.exe -a sb EVAL "$(Get-Content test.lua)" 1 a  b
1) "a"
2) "b"

Is it a real issue, or is my syntax wrong? Thanks in advance, jg

enricogior commented 8 years ago

Hi @jgranduel using the Windows command prompt (not the Windows powershell) the command that didn't work for you, worked for me:

C:\tmp>redis-cli -a sb --eval test.lua a , b
1) "a"
2) "b"

Is it possible that the comma causes the problem when the command is executed in powershell?

jgranduel commented 8 years ago

You are absolutely right! the same here. I should have tested!

So I had the idea of escaping the comma :

PS > redis-cli -a sb --eval test.lua a `, b
1) "a"
2) "b"

Strange syntax, but usable. Thanks