Skip to content

Commit aeca156

Browse files
authored
RED-121350: extend redis-webcli to work with redb service directly
2 parents 1e651a3 + 750639e commit aeca156

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

app.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,13 @@ def return_code(self):
9191
def _execute(command: str):
9292
success = False
9393
try:
94-
conn = get_conn_through_sentinel()
94+
conn = get_conn()
9595
response = conn.execute_command(*command.split())
9696
success = True
9797
except (redis.exceptions.ConnectionError, redis.exceptions.ResponseError):
9898
try:
9999
reload_username_password_from_file_system_if_needed(app)
100-
conn = get_conn_through_sentinel()
100+
conn = get_conn()
101101
response = conn.execute_command(*command.split())
102102
success = True
103103
except Exception as err:
@@ -151,21 +151,30 @@ def reload_username_password_from_file_system_if_needed(app):
151151
app.config["REDIS_USERNAME"] = redis_username
152152

153153

154-
def get_conn_through_sentinel():
155-
# it would be nice to call sentinel.master_for
156-
# redis-py API here. But this does not work
157-
# when the bdb is configured with TLS
158-
# creating the connection directly instead
154+
def get_conn():
155+
if app.config['USE_SENTINEL']:
156+
return _get_sentinel_conn()
157+
else:
158+
return _get_service_conn()
159159

160-
master_info = get_master(app.config['REDIS_URL'])
161-
master_ip = str(master_info[0])
162-
master_port = str(master_info[1])
163160

161+
def _get_service_conn():
162+
return redis.Redis(host=app.config["DB_SERVICE_HOST"],
163+
port=app.config["DB_SERVICE_PORT"],
164+
password=app.config['REDIS_PASSWORD'],
165+
decode_responses=True)
166+
167+
168+
def _get_sentinel_conn():
169+
# it would be nice to call sentinel.master_for redis-py API here. But this does not work when the bdb is configured
170+
# with TLS creating the connection directly instead
171+
172+
master_info = get_master(app.config['REDIS_URL'])
164173
connection_args = {
165-
"host": master_ip,
166-
"port": master_port,
174+
"host": str(master_info[0]),
175+
"port": str(master_info[1]),
167176
"password": app.config['REDIS_PASSWORD'],
168-
"decode_responses" : True
177+
"decode_responses": True
169178
}
170179
redis_username = app.config['REDIS_USERNAME']
171180
if redis_username:

config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ def configure(app):
6363
app.config['SKIP_HOSTNAME_VALIDATION'] = \
6464
get_boolean_val_from_env('REDIS_WEBCLI_SKIP_HOSTNAME_VALIDATION',
6565
False)
66+
app.config['USE_SENTINEL'] = get_boolean_val_from_env('USE_SENTINEL', True)
67+
app.config['DB_SERVICE_HOST'] = os.getenv('DB_SERVICE_HOST')
68+
app.config['DB_SERVICE_PORT'] = os.getenv('DB_SERVICE_PORT')
69+
6670

6771
def should_read_from_file_system():
6872
return get_boolean_val_from_env('READ_FROM_FILE_SYSTEM', False)

0 commit comments

Comments
 (0)