redisluaredis-cluster

Redis Function not found


My setup is a 3 masters, 3 slaves Redis cluster, version 7.x.

I created a simple Lua based function as:

#!lua name=loggerLib
local function logMsg(keys, args)
    redis.log(redis.LOG_NOTICE, 'Hello!');
end
redis.register_function('logMsg', logMsg)

and loaded it as

cat loggerLib.lua | redis-cli -c -p 7000 -x FUNCTION LOAD REPLACE

However, when I execute it from the redis command prompt as 127.0.0.1:7002> FCALL logMsg 1

I see the error: (error) ERR Function not found

What am I doing wrong here?

When I run it as

127.0.0.1:7000> FCALL logMsg 1 a

I see the error

-> Redirected to slot [15495] located at 127.0.0.1:7002
(error) ERR Function not found

Solution

  • I see the error: (error) ERR Function not found

    Because you call FUNCTION LOAD on one node (127.0.0.1:7000), while call FCALL on another node (127.0.0.1:7002). The function is only loaded on 127.0.0.1:7000, and the other node does't have the function loaded.

    You need to call FUNCTION LOAD on every node in your Redis Cluster.

    I see the error

    -> Redirected to slot [15495] located at 127.0.0.1:7002 (error) ERR Function not found

    Because the key that your function tries to operate, located on node 127.0.0.1:7002, and your client is redirected to it, and again, it doesn't have the function loaded.