I have a Redis 7.x cluster with 3 master nodes running on ports 7000, 7001, 7002. Each master has 1 slave/replica.
I am trying to load and run this Lua based function:
#!lua name=printTestLib
local function printTest(keys, args)
local time = redis.call('TIME');
print("current timestamp in millis: " .. time)
end
redis.register_function('printTest', printTest)
When I run it as
127.0.0.1:7000> fcall printTest 0
I see the error:
(error) ERR user_function:4: Script attempted to access nonexistent global variable 'print' script: printTest, on @user_function:4.
What is the issue with the call to print
statement?
You're running the Lua based function with print()
, which doesn't exist since Redis Lua implementation is sandboxed.
You can simply fix this by replacing print
with redis.log
to log the message you're trying to call.