forked from SnobbyDragon/RedisDataCube
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRouter.py
More file actions
46 lines (37 loc) · 1.11 KB
/
Router.py
File metadata and controls
46 lines (37 loc) · 1.11 KB
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
import RedisClient as rc
from bottle import route, run, template, post, get
import re
R_HOST='localhost'
R_PORT=6379
R_DB=0
REDIS_INSTANCE = rc.RedisClient(host=R_HOST, port=R_PORT, db_num=R_DB)
@route('/api/v1/redis')
def index():
val = REDIS_INSTANCE.client.get("hello")
rv = [{ "hello": val}]
print(rv)
return dict(data=rv)
@get('/api/v1/redis/<query>')
def do_query(query):
cubeDict = REDIS_INSTANCE.query_redis(query)
return dict(data=cubeDict)
@get('/api/v1/redis/as_text/<query>')
def do_query(query):
cubeDict = REDIS_INSTANCE.query_redis(query)
cubeText = REDIS_INSTANCE.cube_to_string(cubeDict)
return template('<pre>{{cubeText}}</pre>', cubeText=cubeText)
@get('/api/v1/redis/keys')
def index():
keys = []
for key in REDIS_INSTANCE.client.keys():
possible_key = re.sub(":\d+", "", key)
if possible_key not in keys:
keys.append(possible_key)
return dict(data=keys)
@route('/hello/<name>')
def index(name):
return template('<b>Hello {{name}}</b>!', name=name)
def main():
run(host='localhost', port=8080)
if __name__ == "__main__":
main()