Skip to content

Accessing page_state in result metadata for token based paging #85

@NathanBaulch

Description

@NathanBaulch

I'm trying to implement token based paging in my project's API but it doesn't look like the page_state result metadata is exposed by Cassandra\Response\Result. Is there a recommended way to capture this value so my clients can request the next page at a later time?

For now I'm using the following hack to work around this:

$pageState = null;
while (true) {
    /** @var Result $res */
    $res = $cass->querySync('SELECT "key" FROM message', [], null, ['page_size' => 10, 'paging_state' => $pageState]);
    yield from $res->fetchCol();
    $pageState = CassandraResultMetadataAccessor::getPageState($res);
    if (!$pageState) break;
    echo 'DEBUG: paging token for client: ' . base64_encode($pageState) . "\n";
}

class CassandraResultMetadataAccessor extends Result
{
    public static function getPageState(Result $res) {
        return $res->_metadata['page_state'] ?? null;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions