Search code examples
node.jsluaredis

Error: ERR value is not an integer or out of range from redis.call('zcard','myzset') in LUA script


I have this code in a lua script which I run from node.js.

local stats = {};
stats['orders'] = redis.call('zcard','jobs');

return cjson.encode(stats)

This returns the error :

Error: ERR value is not an integer or out of range

However when I run zcard jobs from the CLI an integer is returned.


Solution

  • Your Lua script works fine. Throw away the semicolons tho, it's Lua ;) .

    Test:

    redis-cli -p 14130 eval "local stats = {} \
    stats['orders'] = redis.call('zcard','azbp.d') \
    return cjson.encode(stats)" 0
    

    Result:

    "{\"orders\":10424}"
    

    My guess is, that your client side call is invalid. The first parameter so pass to EVAL or EVALSHA should be the number of parameters. You must pass 0 in this example. Just guessing ofcourse.

    Hope this helps, TW