def __init__(self):
# register tornado's RequestHandler to designated context path
handlers = [
(r'/publish', PublishHandler),
(r'/subscribe', SubscribeHandler),
(r'/', IndexHandler),
]
settings = dict(
template_path=path.join(path.dirname(__file__), 'templates'),
static_path=path.join(path.dirname(__file__), 'static'),
)
super(Application, self).__init__(handlers, **settings)
# redis singeleton to share among handlers
self.redis = redis.StrictRedis(host=options.redis_host, port=options.redis_port, db=options.redis_db, password=options.redis_password)
# redis pubsub singeleton to share among handler(pubsub is used to subscribe channels)
self.pubsub = self.redis.pubsub(ignore_subscribe_messages=True)
self.pubsub.subscribe(options.redis_channel)
# logger to record log
self.logger = logger
# base handler
评论列表
文章目录