def init_app(self, app, config_prefix=None):
<EOL>if '<STR_LIT>' not in app.extensions:<EOL><INDENT>app.extensions['<STR_LIT>'] = {}<EOL><DEDENT>self.config_prefix = config_prefix = config_prefix or '<STR_LIT>'<EOL>if config_prefix in app.extensions['<STR_LIT>']:<EOL><INDENT>raise ValueError('<STR_LIT>'.<EOL>format(config_prefix))<EOL><DEDENT>converters = {'<STR_LIT:port>': int}<EOL>convert = lambda arg, value: (converters[arg](value)<EOL>if arg in converters<EOL>else value)<EOL>key = lambda param: '<STR_LIT>'.format(config_prefix, param)<EOL>klass = app.config.get(key('<STR_LIT>'), RedisClass)<EOL>if isinstance(klass, string_types):<EOL><INDENT>klass = import_string(klass)<EOL><DEDENT>url = app.config.get(key('<STR_LIT>'))<EOL>if url:<EOL><INDENT>urlparse.uses_netloc.append('<STR_LIT>')<EOL>url = urlparse.urlparse(url)<EOL>app.config[key('<STR_LIT>')] = url.hostname<EOL>app.config[key('<STR_LIT>')] = url.port or <NUM_LIT><EOL>app.config[key('<STR_LIT>')] = url.username<EOL>app.config[key('<STR_LIT>')] = url.password<EOL>db = url.path.replace('<STR_LIT:/>', '<STR_LIT>')<EOL>app.config[key('<STR_LIT>')] = db if db.isdigit() else None<EOL><DEDENT>host = app.config.get(key('<STR_LIT>'))<EOL>if host and (host.startswith('<STR_LIT>') or host.startswith('<STR_LIT:/>')):<EOL><INDENT>app.config.pop(key('<STR_LIT>'))<EOL>app.config[key('<STR_LIT>')] = host<EOL><DEDENT>args = self._build_connection_args(klass)<EOL>kwargs = dict([(arg, convert(arg, app.config[key(arg.upper())]))<EOL>for arg in args<EOL>if key(arg.upper()) in app.config])<EOL>connection = klass(**kwargs)<EOL>app.extensions['<STR_LIT>'][config_prefix] = connection<EOL>self._include_public_methods(connection)<EOL>
Actual method to read redis settings from app configuration, initialize
Redis connection and copy all public connection methods to current
instance.

:param app: :class:`flask.Flask` application instance.
:param config_prefix: Config prefix to use. By default: ``REDIS``