Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- listening 8000
- GroupChat here
- getMsg here
- None
- None
- [I 150401 18:30:57 web:1825] 304 GET /groupchat?key=testc (127.0.0.1) 2.40ms
- Message(kind=u'message', channel=u'testc', body=u'helloword', pattern=u'testc')
- class GroupChat(tornado.web.RequestHandler):
- def initialize(self):
- print 'GroupChat here'
- self.c = tornadoredis.Client(host=CONFIG['REDIS_HOST'], port=CONFIG['REDIS_PORT'], password=CONFIG['REDIS_AUTH'])
- self.channelMsgModel = channelMsgModel(self.c)
- @tornado.gen.coroutine
- def get(self):
- try:
- key = self.get_argument('key')
- info = yield self.channelMsgModel.getMsg(key)
- print info
- self.finish(info)
- except Exception, e:
- print e
- pass
- class channelMsgModel :
- timeout = 10
- def __init__(self, redisobj):
- self.redisobj = redisobj
- @tornado.gen.coroutine
- def getMsg(self, key):
- print 'getMsg here'
- yield tornado.gen.Task(self.redisobj.subscribe, key)
- info = self.redisobj.listen(self.on_message)
- print info
- raise tornado.gen.Return(info)
- def on_message(self, msg):
- if (msg.kind == 'message'):
- print msg
- return msg
- elif (msg.kind == 'unsubscribe'):
- self.redisobj.disconnect()
- # raise tornado.gen.Return(False)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement