flyerhzm / redis-sentinel

another redis automatic master/slave failover solution for ruby by using built-in redis sentinel (deprecated)
MIT License
188 stars 67 forks source link

Bubble up error so that I can kill my server if there is no redis sentinel connection #57

Open ORESoftware opened 9 years ago

ORESoftware commented 9 years ago

If I have these two lines of code:

var Sentinel = sentinel.Sentinel(endpoints); var client = Sentinel.createClient(REDIS_SENTINEL_MASTER_NAME, {role: 'master'});

When Redis is not running, or it is misconfigured, your library will throw an error - Error: Failed to find a sentinel from the endpoints

However, the error is not fatal and my server keeps running.

(1) I want to trap that error and decide if I should kill my server. (2) I want to find out where in my program the error is occurring; as of now, it's hard to track down.

In most sophisticated languages, errors will "bubble up" if you enclose them with a try/catch block:

try{
    var Sentinel = sentinel.Sentinel(endpoints);
    var client = Sentinel.createClient(REDIS_SENTINEL_MASTER_NAME, {role: 'master'});
}
catch(e){
    throw e;
}

but I am unable to trap the errors. Your library throws the error internally, but doesn't give me enough information to trap the error.

Am I using the wrong approach?