nicolasff / webdis

A Redis HTTP interface with JSON output
https://webd.is
BSD 2-Clause "Simplified" License
2.82k stars 307 forks source link

EVALSHA does not seem to work #146

Closed badfd closed 4 years ago

badfd commented 6 years ago

Webdis version: 0.1.3-dev

The following redis-cli commands are successful:

$ redis-cli set foo1 bar1
OK
$ redis-cli set foo2 bar2
OK
redis-cli evalsha 4223a719efc2c7a9678c7fb92b304d61e5d43c32 1 , foo*
1) 1) "foo1"
   2) "bar1"
2) 1) "foo2"
   2) "bar2"

Or, within an interactive session:

$ redis-cli
127.0.0.1:6379> evalsha  4223a719efc2c7a9678c7fb92b304d61e5d43c32  0  foo*
1) 1) "foo1"
   2) "bar1"
2) 1) "foo2"
   2) "bar2"

however, when I attempt the EVALSHA command via Webdis, no in/sane URI seems to work:

$ curl -X GET http://172.20.32.216:7379/evalsha/4223a719efc2c7a9678c7fb92b304d61e5d43c32/0/foo*
{"evalsha":[null,null]}

Oddly enough, if I specify RAW output, I get a correct count of the number of matching key-value pairs:

$ curl -X GET http://172.20.32.216:7379/evalsha/4223a719efc2c7a9678c7fb92b304d61e5d43c32/0/foo*.raw
*2
$ redis-cli set foo3 bar3
OK
$ curl -X GET http://172.20.32.216:7379/evalsha/4223a719efc2c7a9678c7fb92b304d61e5d43c32/0/foo*.raw
*3

Is it the output of my Lua script that's at fault? Can I change the script's output format to make it work?

nicolasff commented 4 years ago

Saving a script that looks like it does the same thing as yours:

$ redis-cli script load "local keys = redis.call('KEYS',ARGV[1]..'*'); local values = redis.call('MGET', unpack(redis.call('KEYS',ARGV[1]..'*'))); local results = {}; for i,key in ipairs(keys) do results[i] = {keys[i],values[i]} end; return results"
"0d76aafa1f7ffcc886e0e205cc22c1fb8fe86315"

$ redis-cli set foo1 bar1
OK

$ redis-cli set foo2 bar2
OK

$ redis-cli evalsha 0d76aafa1f7ffcc886e0e205cc22c1fb8fe86315 0 foo
1) 1) "foo1"
   2) "bar1"
2) 1) "foo2"
   2) "bar2"

And querying with Webdis:

$ curl -s 'http://localhost:7379/evalsha/0d76aafa1f7ffcc886e0e205cc22c1fb8fe86315/0/foo' | jq
{
  "evalsha": [
    [
      "foo1",
      "bar1"
    ],
    [
      "foo2",
      "bar2"
    ]
  ]
}