Advertisement
Guest User

Untitled

a guest
Apr 1st, 2015
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. listening 8000
  2. GroupChat here
  3. getMsg here
  4. None
  5. None
  6.  
  7. [I 150401 18:30:57 web:1825] 304 GET /groupchat?key=testc (127.0.0.1) 2.40ms
  8. Message(kind=u'message', channel=u'testc', body=u'helloword', pattern=u'testc')
  9.  
  10. class GroupChat(tornado.web.RequestHandler):
  11. def initialize(self):
  12. print 'GroupChat here'
  13. self.c = tornadoredis.Client(host=CONFIG['REDIS_HOST'], port=CONFIG['REDIS_PORT'], password=CONFIG['REDIS_AUTH'])
  14. self.channelMsgModel = channelMsgModel(self.c)
  15. @tornado.gen.coroutine
  16. def get(self):
  17. try:
  18. key = self.get_argument('key')
  19. info = yield self.channelMsgModel.getMsg(key)
  20. print info
  21. self.finish(info)
  22. except Exception, e:
  23. print e
  24. pass
  25.  
  26. class channelMsgModel :
  27. timeout = 10
  28. def __init__(self, redisobj):
  29. self.redisobj = redisobj
  30.  
  31. @tornado.gen.coroutine
  32. def getMsg(self, key):
  33. print 'getMsg here'
  34. yield tornado.gen.Task(self.redisobj.subscribe, key)
  35. info = self.redisobj.listen(self.on_message)
  36. print info
  37. raise tornado.gen.Return(info)
  38.  
  39. def on_message(self, msg):
  40. if (msg.kind == 'message'):
  41. print msg
  42. return msg
  43. elif (msg.kind == 'unsubscribe'):
  44. self.redisobj.disconnect()
  45. # raise tornado.gen.Return(False)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement