Skip to content

Commit f328e53

Browse files
committed
added support for tornado's command line options
1 parent 3f1160f commit f328e53

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

src/redis-live.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import tornado.ioloop
44
import tornado.options
5+
from tornado.options import define, options
56
import tornado.web
67

78
from api.controller.BaseStaticFileHandler import BaseStaticFileHandler
@@ -13,20 +14,23 @@
1314
from api.controller.TopCommandsController import TopCommandsController
1415
from api.controller.TopKeysController import TopKeysController
1516

17+
if __name__ == "__main__":
18+
define("port", default=8888, help="run on the given port", type=int)
19+
define("debug", default=0, help="debug mode", type=int)
20+
tornado.options.parse_command_line()
1621

17-
# Bootup
18-
application = tornado.web.Application([
19-
(r"/api/servers", ServerListController),
20-
(r"/api/info", InfoController),
21-
(r"/api/memory", MemoryController),
22-
(r"/api/commands", CommandsController),
23-
(r"/api/topcommands", TopCommandsController),
24-
(r"/api/topkeys", TopKeysController),
25-
(r"/(.*)", BaseStaticFileHandler, {"path": "www"})
26-
], debug="True")
27-
22+
# Bootup
23+
handlers = [
24+
(r"/api/servers", ServerListController),
25+
(r"/api/info", InfoController),
26+
(r"/api/memory", MemoryController),
27+
(r"/api/commands", CommandsController),
28+
(r"/api/topcommands", TopCommandsController),
29+
(r"/api/topkeys", TopKeysController),
30+
(r"/(.*)", BaseStaticFileHandler, {"path": "www"})
31+
]
2832

29-
if __name__ == "__main__":
30-
tornado.options.parse_command_line()
31-
application.listen(8888)
32-
tornado.ioloop.IOLoop.instance().start()
33+
server_settings = {'debug': options.debug}
34+
application = tornado.web.Application(handlers, **server_settings)
35+
application.listen(options.port)
36+
tornado.ioloop.IOLoop.instance().start()

0 commit comments

Comments
 (0)