Steps to reproduce: 1. Load script using SCRIPT LOAD
SCRIPT LOAD "return 'Immabe a cached script'"
Returns c664a3bf70bd1d45c4284ffebb65a6f2299bfc9f 2. Call that script from another lua script
eval "return f_c664a3bf70bd1d45c4284ffebb65a6f2299bfc9f()" 0
I tried with 2 Redis versions. In 6.2.5, it works, but not in 6.2.7
6.2.5 result "Immabe a cached script"
6.2.7 result (error) ERR Error running script (call to f_49a6d7287f77f9ef09e70998d75d580a5b63da29): @user_script:1: user_script:1: Script attempted to access nonexistent global variable 'f_c664a3bf70bd1d45c4284ffebb65a6f2299bfc9f'
How can I get it to work?
================= Below is more details, explain my specific use case I have a long lua script, which contains several functions, let's say they are func_a, func_b, func_c. I'm using ioredis (Nodejs) as my client. For easier access, I use defineCommand to register func_a, func_b, func_c.
Redis.defineCommand('func_a', {
numberOfKeys: 0,
lua: `local e = f_c664a3bf70bd1d45c4284ffebb65a6f2299bfc9f();return e.func_a();`,
});
// Further call will be
Redis.func_a();
Comment From: enjoy-binbin
thanks for report, looks like a regression problem
i tested it, it work in 6.2.6 but doesn't work in 6.2.7 and unstable branch
@MeirShpilraien PTAL
Comment From: oranagra
AFAIK we broke this on purpose.. it was never intended for scripts to call other scripts, and the f_<sha> thing wasn't documented anywhere.
Since the script cache doesn't provide any guarantees, i was always invalid to make the assumption that if one script is still cached, the other is too.
Please note that Functions in redis 7 seem to serve your use case much better.