smrchy/rsmq

Change how lua scripts are loaded/called

jkirkwood opened this issue · 2 comments

Right now all lua scripts are loaded into redis when you create a new rsmq instance. evalsha is called during queue operations in order to run the scripts.

One problem I see with this is what if the Redis database is restarted, the sha1 sums will no longer exist in Redis, and any call to evalsha will throw a NOSCRIPT error. This will continue to happen until you restart rsmq.

What I propose is basically following the guidelines at the end of this section: https://redis.io/commands/eval#bandwidth-and-evalsha. We should not bother loading the scripts to begin with. We should call evalsha by default, but fallback to calling eval if we get a NOSCRIPT error. Subsequent calls to evalsha should then work since the script would then be cached.

RSMQ does a initScripts when Redis connects. So if you shutdown a server and restart it without data that would be called. But losing queues that were there before would result in other errors in your apps.

Currently i don't see the need to change the code.

@smrchy – ah, yes I didn't notice that. My fear with this was that any commands queued while the connection was lost would be run before the scripts we're re-initialized. But after looking at node-redis I see the connect event is handled before pending commands are de-queued, so I think we're ok.