I would like to load one script into redis that will export functions that future scripts executed will depend on, but attempt to define global function fails, same goes for global variables:
redis 127.0.0.1:6379> EVAL "function alex() return 3.1415 end" 0
(error) ERR Error running script (call to f_f24a5a054d91ccc74c2629e113f8f639bbedbfa2): user_script:1: Script attempted to create global variable 'alex'
How can I define global functions and variables ?
Looking at the source code in file scripting.c
The doc-string of
scriptingEnableGlobalsProtection
indicates that intent is to notify script authors of common mistake (not usinglocal
).It looks like this is not security feature, so we have two solutions:
One can remove this protection:
Or use
rawset
: