def redis_listener(): r = redis.Redis(settings.REDIS_HOST, settings.REDIS_PORT) ps = r.pubsub() ps.subscribe(['lookups']) for message in ps.listen(): try: data = tornado.escape.json_decode(message['data']) except ValueError: data = message['data'] #print "****MESSAGE" #pprint(data) #print "\t send this to", len(LookupsConnection.connected_clients), 'clients' to_send = {} for key, value in data.items(): new_key = { 'lookups:json': 'lookups_json', 'lookups:jsonp': 'lookups_jsonp', 'auths:total': 'auths', 'lookups:usernames': 'lookups_usernames' }.get(key) if new_key is None: print "Skipping", repr(key) continue #print new_key, repr(value) to_send[new_key] = value for client in LookupsConnection.connected_clients: client.send(to_send)
def on_message(self, message): logging.debug("RECEIVED: %r" % message) for client in self.connected_clients: if client != self: #print "CLIENT", repr(client) #print "\t", client.is_closed if client.is_closed: print "DBG consider deleting", repr(client) else: client.send({'message': message.upper()})