Exemple #1
0
 def queueList(self, name_start, name_end, page_num, page_size):
     """
     return queue/list items in range(`name_start`, `name_end`)
     Args:
         name_start: The lower bound(not included) of keys to be returned, empty string ``''`` means -inf
         name_end: The upper bound(included) of keys to be returned, empty string ``''`` means +inf
         page_num: page number
         page_size: items size per page
     Returns:
         items list
     """
     limit = (page_num + 1) * page_size
     items_list = [
         _.decode() for _ in self.__conn.execute_command(
             'qlist', name_start, name_end, limit)
     ]
     page_count, page_num = getPagingTabsInfo(data_count=len(items_list),
                                              page_no=page_num,
                                              page_row_num=page_size)
     has_next = True if page_count > page_num else False
     queue_list = map(
         lambda queue_name: {
             'name': queue_name,
             'size': self.__conn.llen(queue_name)
         }, items_list[(page_num - 1) * page_size:page_num * page_size])
     return queue_list, has_next
Exemple #2
0
    def zsetList(self, start, page_num, page_size):
        """
        return zset items in range(`name_start`, `name_end`)
        Args:
            start: The lower bound(not included) of keys to be returned, empty string ``''`` means -inf
            page_num: page number
            page_size: page size

        Returns:
            items list
        """
        limit = (page_num + 1) * page_size
        name_list = [
            _.decode("utf8", "ignore")
            for _ in self.__conn.execute_command('zlist', start, '', limit)
        ]
        page_count, page_num = getPagingTabsInfo(data_count=len(name_list),
                                                 page_no=page_num,
                                                 page_row_num=page_size)
        has_next = True if page_count > page_num else False
        zset_list = map(
            lambda zset_name: {
                'name': zset_name,
                'size': self.__conn.zcard(zset_name)
            }, name_list[(page_num - 1) * page_size:page_num * page_size - 1])
        return zset_list, has_next
Exemple #3
0
def zsetRange():
    """
    show the list of item from zst
    :return:
    """
    set_name = request.args.get('name')
    start = request.args.get('start', "")
    page_num = request.args.get('page_num', 1)
    page_size = request.args.get('page_size')
    if not page_size:
        page_size = request.cookies.get('SIZE', 10)

    db_object = SSDBClient(request)
    item_total = db_object.zsetSize(set_name)
    page_count, page_num = getPagingTabsInfo(item_total, page_num, page_size)
    offset = (page_num - 1) * int(page_size)
    if start:
        rank = db_object.zsetRank(set_name, start)
        if rank:
            page_num = getPageNumberInfo(rank, page_count, page_size)
            offset = (page_num - 1) * int(page_size)

    item_list = db_object.zsetRange(set_name, offset=offset, limit=page_size)
    select_arg = {'page_size': int(page_size)}
    resp = make_response(
        render_template('zset/zset_range.html',
                        item_list=item_list,
                        name=set_name,
                        page_num=int(page_num),
                        page_count=page_count,
                        select_arg=select_arg,
                        start=start,
                        active='zset'))
    resp.set_cookie('SIZE', str(page_size), httponly=True, samesite='Lax')
    return resp
Exemple #4
0
def queueRange():
    """
    show the list of item from queue
    :return:
    """
    queue_name = request.args.get('name')
    start = request.args.get('start')
    page_num = request.args.get('page_num', 1)
    page_size = request.args.get('page_size')
    if not page_size:
        page_size = request.cookies.get('SIZE', "10")

    db_object = SSDBClient(request)
    item_total = db_object.queueSize(queue_name)
    page_count, page_num = getPagingTabsInfo(item_total, page_num, page_size)
    offset = (page_num - 1) * int(page_size)
    if start and start.isdigit():
        page_num = getPageNumberInfo(int(start), page_count, page_size)
        offset = (page_num - 1) * int(page_size)
    else:
        start = offset

    item_list = db_object.queueRange(queue_name,
                                     offset=offset,
                                     limit=page_size)
    select_arg = {'page_size': int(page_size)}
    resp = make_response(
        render_template('queue/queue_range.html',
                        item_list=item_list,
                        name=queue_name,
                        page_num=int(page_num),
                        page_count=page_count,
                        select_arg=select_arg,
                        start_index=offset,
                        start=start,
                        data_total=item_total,
                        active='queue'))
    resp.set_cookie('SIZE', page_size, httponly=True, samesite='Lax')
    return resp