|
| 1 | +import inspect |
1 | 2 | import threading |
2 | 3 | import time |
3 | 4 | import subprocess |
|
11 | 12 | from flask import Flask, render_template, request, jsonify, abort |
12 | 13 | from flask import current_app as capp |
13 | 14 | from flask_redis_sentinel import SentinelExtension |
| 15 | +import flask_redis_sentinel |
14 | 16 | from flask_bootstrap import Bootstrap |
15 | 17 | from config import configure, should_read_from_file_system, get_username_and_password_from_file_system |
16 | 18 | import redis_sentinel_url |
17 | 19 | import redis |
18 | 20 |
|
| 21 | + |
| 22 | +class MyOverride(object): |
| 23 | + @classmethod |
| 24 | + def _my_config_from_variables(cls, config, the_class): |
| 25 | + args = inspect.getfullargspec(the_class.__init__).args |
| 26 | + args.remove('self') |
| 27 | + args.remove('host') |
| 28 | + args.remove('port') |
| 29 | + args.remove('db') |
| 30 | + return {arg: config[arg.upper()] for arg in args if arg.upper() in config} |
| 31 | + |
| 32 | +flask_redis_sentinel.RedisSentinel._config_from_variables = MyOverride._my_config_from_variables |
19 | 33 | redis_sentinel = SentinelExtension() |
20 | 34 | sentinel = redis_sentinel.sentinel |
21 | 35 |
|
| 36 | + |
22 | 37 | app = Flask(__name__) |
23 | 38 |
|
24 | 39 | configure(app) |
@@ -94,9 +109,6 @@ def execute(): |
94 | 109 | response = 'Exception: %s' % str(err) |
95 | 110 | app.logger.exception("execute err") |
96 | 111 |
|
97 | | - if isinstance(response, bytes): |
98 | | - response = response.decode("utf-8") |
99 | | - |
100 | 112 | return jsonify({ |
101 | 113 | 'response': response, |
102 | 114 | 'success': success |
@@ -127,15 +139,16 @@ def get_conn_through_sentinel(): |
127 | 139 | connection_args = { |
128 | 140 | "host": master_ip, |
129 | 141 | "port": master_port, |
130 | | - "password": app.config['REDIS_PASSWORD'] |
| 142 | + "password": app.config['REDIS_PASSWORD'], |
| 143 | + "decode_responses" : True |
131 | 144 | } |
132 | 145 | redis_username = app.config['REDIS_USERNAME'] |
133 | 146 | if redis_username: |
134 | 147 | # if no user name is sent, Redis will use the default username. |
135 | 148 | connection_args['username'] = redis_username |
136 | 149 |
|
137 | 150 | if app.config['SSL_ENABLED']: |
138 | | - ssl_cert_reqs = None if app.config['SKIP_HOSTNAME_VALIDATION'] else 'required' |
| 151 | + ssl_cert_reqs = "none" if app.config['SKIP_HOSTNAME_VALIDATION'] else 'required' |
139 | 152 | connection_args['ssl'] = True |
140 | 153 | connection_args['ssl_cert_reqs'] = ssl_cert_reqs |
141 | 154 |
|
|
0 commit comments