def retrieve(short_url): """ Retrieve the origin url from the short url """ v = redis_cli.get(f'url:{short_url}') if not v: raise ApiException('The url not register yet') u = Url.parse_raw(v) redis_cli.expire(u.redis_key, u.SHORT_URL_EXPIRE_SECONDS) return jsonify({'origin_url': u.origin_url})
def list_(): """ List registered urls """ keys = [k for k in redis_cli.scan_iter(match='url*', count=1000)] if not keys: return jsonify({'urls': []}) # TODO: Pagination PAGE_SIZE = 25 url_list = [ Url.parse_raw(v).dict() for v in redis_cli.mget(*keys[-PAGE_SIZE:]) ] return jsonify({'urls': url_list})