Don't crash the app if Redis is unavailable on start
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.
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.
Let's aim to have this for v2.0.0
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?
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 look at Kryten0807 comment
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.