-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
56 lines (47 loc) · 1.31 KB
/
app.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from flask import Flask
import redis
app = Flask(__name__)
redis_host = "redis-svc"
redis_port = 6379
redis_password = ""
@app.route('/')
def hi():
return "Hello!"
@app.route('/test')
def test_conn():
try:
r = redis.StrictRedis(host=redis_host, port=redis_port, password=redis_password, decode_responses=True)
rs = r.client_list() # Check redis connection
return('Success')
except Exception as e:
#print(e)
return('Failed')
@app.route('/ping')
def ping():
try:
r = redis.StrictRedis(host=redis_host, port=redis_port, password=redis_password, decode_responses=True)
rs = r.client_list()
pong = r.get('ping')
if pong == None:
pong = 1
r.set("ping", pong)
else:
pong = int(pong)
pong += 1
r.set("ping", pong)
pong = r.get('ping')
return(pong)
except Exception as e:
#print(e)
return('Failed')
@app.route('/del_ping')
def del_ping():
try:
r = redis.StrictRedis(host=redis_host, port=redis_port, password=redis_password, decode_responses=True)
# rs = r.client_list()
r.delete('ping')
except Exception as e:
#print(e)
return('Failed')
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0')