def add_order(r: redis.client.Redis, order: Order):
    if order.side == "Buy":
        topic_name = redis_buy_prices_name
    else:
        topic_name = redis_sell_prices_name
    r.zadd(topic_name, {order.order_id: order.price})
    r.hset(redis_order_sizes_name, key=order.order_id, value=order.size)
    r.hset(redis_account_names_name, key=order.order_id, value=order.username)
示例#2
0
def post_article(conn: redis.client.Redis, user: str, title: str,
                 link: str) -> str:
    """
    添加文章
    """
    article_id = str(conn.incr(ARTICLE_NAME))
    voted = f'{VOTED_NAME}{article_id}'
    conn.sadd(voted, user)
    conn.expire(voted, ONE_WEEK_IN_SECONDS)  # 设置过去时间
    article = f'{ARTICLE_NAME}{article_id}'
    now = time.time()
    conn.hmset(article,
               dict(title=title, link=link, poster=user, time=now, votes=1))
    # before
    # zadd(name,key1,value1,key2,value2)
    # now
    # zadd(name,{key1:value1,key2:value2})
    conn.zadd(SCORE_NAME, {article: now + VOTE_SCORE})
    conn.zadd(TIME_NAME, {article: now})
    return article_id