The problem/use-case that the feature addresses
When implementing a Lua script, there are occasions when it's desired for the script to run as soon as the server starts.
eg: SCRIPT LOAD immediately after running ./redis-server
Without the ability to do this, there are inconvenient and insecure workarounds (described below) that have to be considered
Description of the feature
It would be great to have a configuration variable in redis.conf to define a directory for Redis to import lua scripts. eg:
- lua-import-dir /etc/redis/lua
Alternatives you've considered
Without this config variable, these are some things that might otherwise be implemented:
- Modifying/Adding systemd services to run a shell script that then executes
redis-cliand runsSCRIPT LOAD. The downsides of this are: - It's an extra layer of management and potential issues (and systemd can get tricky for some folks).
-
For folks who may have AUTH/ACL implemented, the shell script will have the credentials in plain text. Obviously, this could be addressed with proper permissions, but I think it's a reasonable assumption that a significant number of people might forget to do this.
-
Having the calling code check that the script is loaded via
SCRIPT EXISTSand, if not, runSCRIPT LOADto upload the script. The downsides of this are: - Added complexity to the logic of the caller.
- When the callers are multiple remote nodes, it's a lot of potentially-unnecessary hauling around of the Lua script(s) to each node.
Additional information
One final piece of this that might be worth considering is the ability to label/name the Lua script that is uploaded, beyond just the SHA. The reason for this would be when you have multiple remote nodes calling the Lua script, to update the Lua script requires one of the at least two following things to occur immediately after:
1. All code on the callers must be updated with the new SHA. Or
2. The SHA must be stored as a value for a key. When the caller sees that the old SHA is no longer available, it would then run something like GET some_lua_script to retrieve the new SHA value.
If it was possible to assign a label/key to a Lua script, the callers could then call that Lua script's label, and it would run properly regardless of if the Lua script has been updated on the server.
Comment From: oranagra
I'm not certain I fully understand the problem you wanna solve. I.e. You said you want the scripts to be loaded at startup, but I'm not certain I understand why... (e.g. Do you want them to also be automatically executed at startup?)
Anyway, the design behind EVAL is that it's part of the client application, not the server. This way there's no need to worry about version of the script you run (that's why there's a SHA and not a name), and the caller is responsible to have a copy of the script (EVALSHA is just an additional optimization layer).
Please have a look at a new scripting feature we're cooking for redis 7.0: #8693