-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.py
More file actions
38 lines (28 loc) · 791 Bytes
/
api.py
File metadata and controls
38 lines (28 loc) · 791 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"""Service to return a sert of counters defined in REDIS."""
from flask import Flask, jsonify
from flask_redis import FlaskRedis
import os
app = Flask(__name__)
pwd = os.environ.get('REDIS_PASSWORD')
host = os.environ.get('REDIS_HOST')
if pwd:
pwd = ":" + pwd
else:
pwd = ""
REDIS_URL = "redis://" + pwd + "@" + host + ":6379"
app.config['REDIS_URL'] = REDIS_URL
redis_store = FlaskRedis(app)
@app.route('/<counters>', methods=['GET'])
def list_messages(counters):
"""List Counters."""
keys = counters.split(",")
resp = {}
for key in keys:
resp[key] = redis_store.get(key).decode('utf-8')
return jsonify(counters=resp)
if __name__ == '__main__':
app.run(
host='0.0.0.0',
port=5000,
debug=True,
threaded=True)