@route('/archivepage')
def archive_page():
    (browser_type, archive, url) = get_params()
    response_key = get_cache_key(archive, browser_type, url)
    wait_key = get_wait_key(archive, browser_type, url)
    queue_key = get_queue_key(browser_type)
    result = None
    if (not rc.exists(response_key)):
        cmd = dict(request.query)
        cmd['url'] = url
        num = rc.incr(('total_urls:' + browser_type))
        cmd['num'] = num
        cmd = json.dumps(cmd)
        with pipeline(rc) as pi:
            waiting_str = {'archived': False, 'queued': True, 'num': num}
            pi.set(response_key, json.dumps(waiting_str))
            pi.rpush(queue_key, cmd)
        rc.blpop(wait_key, theconfig['wait_timeout_secs'])
    result = rc.get(response_key)
    if result:
        result = json.loads(result)
        if ('queued' in result):
            result['queue_pos'] = 0
            front = rc.lindex(queue_key, 0)
            if front:
                front = json.loads(front)
                front_num = front.get('num', 0)
                pos = ((result['num'] - front_num) + 1)
                result['queue_pos'] = pos
        else:
            result['ttl'] = rc.ttl(response_key)
    else:
        result = ERROR_RESP
    return result
@route('/archivepage')
def archive_page():
    (browser_type, archive, url) = get_params()
    response_key = get_cache_key(archive, browser_type, url)
    wait_key = get_wait_key(archive, browser_type, url)
    queue_key = get_queue_key(browser_type)
    result = None
    if (not rc.exists(response_key)):
        cmd = dict(request.query)
        cmd['url'] = url
        num = rc.incr(('total_urls:' + browser_type))
        cmd['num'] = num
        cmd = json.dumps(cmd)
        with pipeline(rc) as pi:
            waiting_str = {'archived': False, 'queued': True, 'num': num}
            pi.set(response_key, json.dumps(waiting_str))
            pi.rpush(queue_key, cmd)
        rc.blpop(wait_key, theconfig['wait_timeout_secs'])
    result = rc.get(response_key)
    if result:
        result = json.loads(result)
        if ('queued' in result):
            result['queue_pos'] = 0
            front = rc.lindex(queue_key, 0)
            if front:
                front = json.loads(front)
                front_num = front.get('num', 0)
                pos = ((result['num'] - front_num) + 1)
                result['queue_pos'] = pos
        else:
            result['ttl'] = rc.ttl(response_key)
    else:
        result = ERROR_RESP
    return result