unable to execute lua scripts with hiredis

284 views
Skip to first unread message

usergoodvery

unread,
Feb 4, 2016, 7:58:54 AM2/4/16
to Redis DB
Hi,

I am having issues getting the hiredis client to execute a loaded lua script. I am able to execute the script via redis-cli and get expected output, but not pragmatically using hiredis.
Not even SCRIPT EXISTS is properly returning.

 when I issue:
1)
redis=redisCommand(ctx, "SCRIPT EXISTS 3a94e53b4b39b8229102c70d92a4ac3f6f8e3c1f");
I tested for all possible return values but only (redis->type == REDIS_REPLY_ARRAY) was true, but element[0]->str is NULL all other return types are false. The same command executed in redis-cli returns OK. I trapped the final protocol string and it seesm to be formatted correctly (see below)

2)
Attempting to run EVALSHA also fails in a very peculiar way:
redis=redisCommand(ctx, "EVALSHA %s 4 %d %d %d %d","3a94e53b4b39b8229102c70d92a4ac3f6f8e3c1f", 4095, 1, 1023, 1);
redis->elements returns '5' which is correct, as the lua script returns 5 values, but then accessing the array elements  elment[0-4]->str are all NULL
The script works fine from redis-cli

Is there a special provision for running LUA scripts from hiredis?


'HIREDIS: cmd: '*3
$6
SCRIPT
$6
EXISTS
$40
3a94e53b4b39b8229102c70d92a4ac3f6f8e3c1f

'HIREDIS: cmd: '*7
$7
EVALSHA
$40
3a94e53b4b39b8229102c70d92a4ac3f6f8e3c1f
$1
4
$4
4095
$1
1
$4
1023
$1
1

Ramon Snir

unread,
Feb 4, 2016, 8:13:35 AM2/4/16
to Redis DB
From reading the hiredis README page:

Did you try using ->integer instead of ->str?

SCRIPT EXISTS returns an array of integers (each 1 or 0, depending on if the supplied SHA at that place is an existing script), and I'm guessing that your lua script also returns a table of integers (as its input is a table of integers).
Reply all
Reply to author
Forward
0 new messages