3 ms·
Is there a way to automatically load a script or a directory of scripts when the redis-server starts?
by kawsper 10y ago
Is there a way to automatically load a script or a directory of scripts when the redis-server starts?
- justinhj 10y agoI don't think that's the recommended way of doing things. Redis will cache compiled Lua scripts internally so after the first EVAL you can call EVALSHA and pass the scripts hash. But you're client code should always be ready for the case that maybe the script is not there any more. In which case you call eval again. Automated tools that upload all the scripts would have no way to say "compile and cache this but don't run it" so you'd need your scripts to handle not doing anything. The usual pattern, then, is to simply send EVALSHA always and if it fails then call EVAL. With small numbers of scripts and larges numbers of operations this will be more efficient and doesn't require any co-ordination with the Redis server when scripts change or servers restart.
- ryanworl 10y agohttp://redis.io/commands/script-load http://redis.io/commands/script-load While I agree that the caller should be ready for a script not existing, one could build an automated tool to load scripts when starting redis using the SCRIPT LOAD command.