redis / ioredis

🚀 A robust, performance-focused, and full-featured Redis client for Node.js.
MIT License
14.43k stars 1.2k forks source link

Execute script with caching but no definedCommand #1027

Closed ethanresnick closed 4 years ago

ethanresnick commented 4 years ago

I have a class that accepts an ioredis instance as a parameter and uses it to make some redis calls. One of those calls requires running a script, and I'd like to be able to take advantage of the logic that first attempts to run the script by SHA, rather than sending the script text each time. However, I don't want my class to have to call defineCommand on the ioredis instance it's passed, as it doesn't "own" that instance, and shouldn't be mutating it in ways that are visible from the outside.

As far as I can tell, the Script.ts file that contains the EVALSHA logic is not exported anywhere/not part of this module's public interface. Could that class be exported, so that I can create a script and run it (by passing the instance to script.execute) without having to mutate the ioredis instance (or import the Script class despite it not being part of the public API)?

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 7 days if no further activity occurs, but feel free to re-open a closed issue if needed.

ethanresnick commented 4 years ago

I feel like this should be reopened, as it hasn't been addressed at all (even to say it's invalid/won't be supported).

Also, @luin, maybe it'd be worth turning down the aggressiveness of the stale bot a little bit? It's somewhat annoying to spend time opening an issue only for a bot to automatically close it (and without a way to reopen it myself).

TysonAndre commented 3 years ago

Another use case for this:

Consider an application using a Proxy<Redis> or Proxy<RedisCluster> in case a config needs to change at runtime (e.g. to change the hostname, or to switch to Redis Cluster, or to change a prefix) (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy)

In that case, when the redis instance belonging to the Proxy is switched to a newly constructed instance, all of the dynamic properties defined with defineCommand would be lost.

As far as I can tell, the Script.ts file that contains the EVALSHA logic is not exported anywhere/not part of this module's public interface. Could that class be exported, so that I can create a script and run it (by passing the instance to script.execute) without having to mutate the ioredis instance (or import the Script class despite it not being part of the public API)?

Having a low level api would be something I'd personally consider useful for