redis-py icon indicating copy to clipboard operation
redis-py copied to clipboard

Feature Request: Create Script object from SHA of a preloaded script

Open PaulKGrimes opened this issue 2 years ago • 1 comments

We are using redis-py for communication across a large local network of computers (to control a multi-antenna interferometric astronomical telescope). In our system for this, we load a number of Lua scripts to the Redis server on start up, and store their SHAs in a table on the server. Redis clients that connect to the server can get those SHAs from the server, and then call the scripts (there's a fall back where the SHAs are retrieved by the clients on NoScriptError, in case the scripts have changed).

The rationale behind this scheme is to have central control of the Lua scripts, so that the Redis clients don't need to be restarted for tweaks to the Lua scripts, and to ensure that all clients are operating the Redis database in the same way.

In Python client code, it would be great if we could create redis.Script objects directly from these SHAs to handle the keys and arguments, rather than by loading a script and calculating a possibly wrong SHA. What I think would be required to implement this is either a class method in Script to create a new instance from the SHA, or some mechanism for determining if the script argument is Lua or a SHA.

We have obvious workarounds available by creating our own version of the Script object that is initialized that way, or by taking the Script.__call__ code and implementing our own function for that, but I thought that this might be a useful feature for wider use.

PaulKGrimes avatar Jan 20 '23 16:01 PaulKGrimes