Exemplo n.º 1
0
def _timer(channel):
    global _signal
    count = 0
    r = get_redis()
    while not _signal['redis']:
        md_str = json.dumps({"message": "Hello World!!", "count": count})
        r.publish(channel, md_str)
        logger.debug("发布成功 %s", md_str)
        count += 1
        if count >= 15:
            break
        time.sleep(1)
Exemplo n.º 2
0
def _timer(channel):
    global _signal
    count = 0
    r = get_redis()
    while not _signal['redis']:
        md_str = json.dumps({"message": "Hello World!!", "count": count})
        r.publish(channel, md_str)
        logger.debug("发布成功 %s", md_str)
        count += 1
        if count >= 15:
            break
        time.sleep(1)
Exemplo n.º 3
0
 def _receiver(channel):
     # 接收订阅的行情,成功接收后退出
     global _signal
     redis_client = get_redis()
     pub_sub = redis_client.pubsub()
     pub_sub.psubscribe(channel)
     for item in pub_sub.listen():
         logger.debug("接收成功 %s", item)
         if item['type'] == 'pmessage':
             md_dic_str = bytes_2_str(item['data'])
             md_dic = json.loads(md_dic_str)
             if "message" in md_dic and "count" in md_dic:
                 _signal['redis'] = True
                 logger.debug("接收到消息")
                 break
Exemplo n.º 4
0
 def _receiver(channel):
     # 接收订阅的行情,成功接收后退出
     global _signal
     redis_client = get_redis()
     pub_sub = redis_client.pubsub()
     pub_sub.psubscribe(channel)
     for item in pub_sub.listen():
         logger.debug("接收成功 %s", item)
         if item['type'] == 'pmessage':
             md_dic_str = bytes_2_str(item['data'])
             md_dic = json.loads(md_dic_str)
             if "message" in md_dic and "count" in md_dic:
                 _signal['redis'] = True
                 logger.debug("接收到消息")
                 break
Exemplo n.º 5
0
 def connect(self):
     """链接redis、初始化历史数据"""
     redis_client = get_redis()
     self.pub_sub = redis_client.pubsub()
Exemplo n.º 6
0
 def connect(self):
     """链接redis、初始化历史数据"""
     redis_client = get_redis()
     self.pub_sub = redis_client.pubsub()