express-redis-cache icon indicating copy to clipboard operation
express-redis-cache copied to clipboard

Don't crash the app if Redis is unavailable on start

Open MichaelMarkieta opened this issue 8 years ago • 6 comments

Just like cache.route() doesn't crash the app if the Redis instance becomes unavailable, the instantiation of the cache should not crash the app if Redis is unavailable at the time of creation.

MichaelMarkieta avatar Mar 15 '17 15:03 MichaelMarkieta

Apart from not crashing the app on start, it shouldn't cause a crash if redis becomes unavailable on runtime.

After digging into the code I think this.emit('error', error') is the problem and should be replaced with a console.error(). https://github.com/rv-kip/express-redis-cache/blob/master/lib/ExpressRedisCache.js#L85

@rv-kip what do you think abt this adjustment? Would be great to use the middleware without the risk of crashing my app.

SassNinja avatar Jul 06 '18 09:07 SassNinja

Let's aim to have this for v2.0.0

krazyjakee avatar Aug 10 '18 11:08 krazyjakee

Maybe I'm misreading the issues that earlier posters have, but I encountered this and solved it, simply by ensuring that I included:

cache.on("error", function(error) {
  console.error("cache", error);
});

The error listener seems to be required; without it, the application fails at startup. Perhaps this just needs to be clarified in the documentation?

kryten87 avatar Aug 29 '18 19:08 kryten87

The error listener seems to be required; without it, the application fails at startup. Perhaps this just needs to be clarified in the documentation? – @Kryten0807

I don't get any error on startup and I don't have such an event listener defined. But I've tried it anyway: unfortunately the error still remains. My app crashes when I kill the redis server while it's running.

SassNinja avatar Aug 30 '18 07:08 SassNinja

SassNinja look at Kryten0807 comment

kibernetika avatar Dec 12 '18 00:12 kibernetika

Seems another redis package was also crashing the app when it became unavailable. That's why I thought it's not working.

I can confirm it's working as described by @Kryten0807 Once you've defined an error listener the app doesn't get crashed anymore if redis becomes unavailable.

However I agree the docs should be clearer and mention this.

SassNinja avatar Jan 08 '19 09:01 SassNinja