from redis import sentinel, StrictRedis


class Sentinel(object):

    def __init__(self, app=None):
        self.app = app
        self.master = StrictRedis()
        self.slave = self.master
        if app is not None: # pragma: no cover
            self.init_app(app)

    def init_app(self, app):
        self.connection = sentinel.Sentinel(app.config['REDIS_SENTINEL'],
                                                  socket_timeout=0.1)
        redis_db = app.config.get('REDIS_DB') or 0
        self.master = self.connection.master_for('mymaster', db=redis_db)
        self.slave = self.connection.slave_for('mymaster', db=redis_db)

from redis import sentinel, StrictRedis


class Sentinel(object):

    def __init__(self, app=None):
        self.app = app
        self.master = StrictRedis()
        self.slave = self.master
        if app is not None: # pragma: no cover
            self.init_app(app)

    def init_app(self, app):
        self.connection = sentinel.Sentinel(app.config['REDIS_SENTINEL'],
                                            socket_timeout=0.1,
                                            retry_on_timeout=True)
        redis_db = app.config.get('REDIS_DB') or 0
        self.master = self.connection.master_for('mymaster', db=redis_db)
        self.slave = self.connection.slave_for('mymaster', db=redis_db)

Add retry on timeout option to sentinel connection
Add retry on timeout option to sentinel connection

  from redis import sentinel, StrictRedis
  
  
  class Sentinel(object):
  
      def __init__(self, app=None):
          self.app = app
          self.master = StrictRedis()
          self.slave = self.master
          if app is not None: # pragma: no cover
              self.init_app(app)
  
      def init_app(self, app):
          self.connection = sentinel.Sentinel(app.config['REDIS_SENTINEL'],
-                                                   socket_timeout=0.1)
+                                             socket_timeout=0.1,
+                                             retry_on_timeout=True)
          redis_db = app.config.get('REDIS_DB') or 0
          self.master = self.connection.master_for('mymaster', db=redis_db)
          self.slave = self.connection.slave_for('mymaster', db=redis_db)
  
Add retry on timeout option to sentinel connection
## Code Before:
from redis import sentinel, StrictRedis


class Sentinel(object):

    def __init__(self, app=None):
        self.app = app
        self.master = StrictRedis()
        self.slave = self.master
        if app is not None: # pragma: no cover
            self.init_app(app)

    def init_app(self, app):
        self.connection = sentinel.Sentinel(app.config['REDIS_SENTINEL'],
                                                  socket_timeout=0.1)
        redis_db = app.config.get('REDIS_DB') or 0
        self.master = self.connection.master_for('mymaster', db=redis_db)
        self.slave = self.connection.slave_for('mymaster', db=redis_db)

## Instruction:
Add retry on timeout option to sentinel connection
## Code After:
from redis import sentinel, StrictRedis


class Sentinel(object):

    def __init__(self, app=None):
        self.app = app
        self.master = StrictRedis()
        self.slave = self.master
        if app is not None: # pragma: no cover
            self.init_app(app)

    def init_app(self, app):
        self.connection = sentinel.Sentinel(app.config['REDIS_SENTINEL'],
                                            socket_timeout=0.1,
                                            retry_on_timeout=True)
        redis_db = app.config.get('REDIS_DB') or 0
        self.master = self.connection.master_for('mymaster', db=redis_db)
        self.slave = self.connection.slave_for('mymaster', db=redis_db)
