I have a Redis cluster v7.x with 3 masters each having 1 slave.
A function myFunc written in Lua is loaded in all the 3 master nodes. I am calling this function from my node.js code (caller.js) using ioredis client library as:
let redis = require('ioredis');
const cluster = new redis.Cluster(
[
{
port: 5000,
host: "localhost"
},
{
port: 5001,
host: "localhost"
},
{
port: 5002,
host: "localhost"
}
]
);
//...
cluster.fcall("myFunc", "0", "arg1", "arg2", "arg3").then((elements) => {
console.log(elements);
});
When I run the program as following:
nodejs caller.js
then sometimes it runs and logs the return value, and sometimes it throws the following error:
(node:2809539) UnhandledPromiseRejectionWarning: ReplyError: ERR Script attempted to access a non local key in a cluster node script: myFunc, on @user_function:66.
at parseError (/home/user/node_modules/redis-parser/lib/parser.js:179:12)
at parseType (/home/user/node_modules/redis-parser/lib/parser.js:302:14)
The myFunc Lua based function uses a sorted set in Redis. The sorted set would be stored on a particular master, not all the masters.
What could be wrong here? How to make the function call work?