skip to Main Content

I’m using ioredis.
In order to prevent a huge buffer that can crash my app, I want to ignore requests when redis is down, and to catch those requests.
Is there any way to achieve that?

2

Answers


  1. You may use circuit breaker design pattern.

    Circuit breaker is a design pattern used in modern software development. It is used to detect failures and encapsulates the logic of preventing a failure from constantly recurring, during maintenance, temporary external system failure or unexpected system difficulties.

    Generally Circuit Breaker can be used to check the availability of an external service. An external service can be a database server or a web service used by the application.

    Martin fowler’s blog post has a good explanation and a basic implementation about how to do it.

    Login or Signup to reply.
  2. For other people finding this who want a bit more help. This intercepts commends to ioredis and just returns false if it’s not in a ready state.

    // Proxify commands to redis client.
    // If redis is unavailable then return false.
    // This stops everything dying if redis is down.
    module.exports.redis = new Proxy(client, {
      get(target, property, receiver) {
        if (client.status !== 'ready') {
          return (() => false);
        }
        return Reflect.get(target, property, receiver);
      },
    });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search